mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
Add RETURNING support to MERGE.
This allows a RETURNING clause to be appended to a MERGE query, to return values based on each row inserted, updated, or deleted. As with plain INSERT, UPDATE, and DELETE commands, the returned values are based on the new contents of the target table for INSERT and UPDATE actions, and on its old contents for DELETE actions. Values from the source relation may also be returned. As with INSERT/UPDATE/DELETE, the output of MERGE ... RETURNING may be used as the source relation for other operations such as WITH queries and COPY commands. Additionally, a special function merge_action() is provided, which returns 'INSERT', 'UPDATE', or 'DELETE', depending on the action executed for each row. The merge_action() function can be used anywhere in the RETURNING list, including in arbitrary expressions and subqueries, but it is an error to use it anywhere outside of a MERGE query's RETURNING list. Dean Rasheed, reviewed by Isaac Morland, Vik Fearing, Alvaro Herrera, Gurjeet Singh, Jian He, Jeff Davis, Merlin Moncure, Peter Eisentraut, and Wolfgang Walther. Discussion: http://postgr.es/m/CAEZATCWePEGQR5LBn-vD6SfeLZafzEm2Qy_L_Oky2=qw2w3Pzg@mail.gmail.com
This commit is contained in:
@@ -2063,9 +2063,10 @@ SELECT <replaceable>select_list</replaceable> FROM <replaceable>table_expression
|
||||
Table Expressions or <acronym>CTE</acronym>s, can be thought of as defining
|
||||
temporary tables that exist just for one query. Each auxiliary statement
|
||||
in a <literal>WITH</literal> clause can be a <command>SELECT</command>,
|
||||
<command>INSERT</command>, <command>UPDATE</command>, or <command>DELETE</command>; and the
|
||||
<command>INSERT</command>, <command>UPDATE</command>, <command>DELETE</command>,
|
||||
or <command>MERGE</command>; and the
|
||||
<literal>WITH</literal> clause itself is attached to a primary statement that can
|
||||
be a <command>SELECT</command>, <command>INSERT</command>, <command>UPDATE</command>,
|
||||
also be a <command>SELECT</command>, <command>INSERT</command>, <command>UPDATE</command>,
|
||||
<command>DELETE</command>, or <command>MERGE</command>.
|
||||
</para>
|
||||
|
||||
@@ -2599,8 +2600,8 @@ SELECT * FROM w AS w1 JOIN w AS w2 ON w1.f = w2.f;
|
||||
<title>Data-Modifying Statements in <literal>WITH</literal></title>
|
||||
|
||||
<para>
|
||||
You can use most data-modifying statements (<command>INSERT</command>,
|
||||
<command>UPDATE</command>, or <command>DELETE</command>, but not
|
||||
You can use data-modifying statements (<command>INSERT</command>,
|
||||
<command>UPDATE</command>, <command>DELETE</command>, or
|
||||
<command>MERGE</command>) in <literal>WITH</literal>. This
|
||||
allows you to perform several different operations in the same query.
|
||||
An example is:
|
||||
|
Reference in New Issue
Block a user