@@ -37,6 +37,7 @@ INSERT INTO <replaceable class="parameter">table_name</replaceable> [ AS <replac
37
37
<phrase>and <replaceable class="parameter">conflict_action</replaceable> is one of:</phrase>
38
38
39
39
DO NOTHING
40
+ DO SELECT [ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } ]
40
41
DO UPDATE SET { <replaceable class="parameter">column_name</replaceable> = { <replaceable class="parameter">expression</replaceable> | DEFAULT } |
41
42
( <replaceable class="parameter">column_name</replaceable> [, ...] ) = [ ROW ] ( { <replaceable class="parameter">expression</replaceable> | DEFAULT } [, ...] ) |
42
43
( <replaceable class="parameter">column_name</replaceable> [, ...] ) = ( <replaceable class="parameter">sub-SELECT</replaceable> )
@@ -88,18 +89,24 @@ INSERT INTO <replaceable class="parameter">table_name</replaceable> [ AS <replac
88
89
89
90
<para>
90
91
The optional <literal>RETURNING</literal> clause causes <command>INSERT</command>
91
- to compute and return value(s) based on each row actually inserted
92
- (or updated, if an <literal>ON CONFLICT DO UPDATE</literal> clause was
93
- used). This is primarily useful for obtaining values that were
92
+ to compute and return value(s) based on each row actually inserted.
93
+ If an <literal>ON CONFLICT DO UPDATE</literal> clause was used,
94
+ <literal>RETURNING</literal> also returns tuples which were updated, and
95
+ in the presence of an <literal>ON CONFLICT DO SELECT</literal> clause all
96
+ input rows are returned. With a traditional <command>INSERT</command>,
97
+ the <literal>RETURNING</literal> clause is primarily useful for obtaining
98
+ values that were
94
99
supplied by defaults, such as a serial sequence number. However,
95
100
any expression using the table's columns is allowed. The syntax of
96
101
the <literal>RETURNING</literal> list is identical to that of the output
97
- list of <command>SELECT</command>. Only rows that were successfully
102
+ list of <command>SELECT</command>. If an <literal>ON CONFLICT DO SELECT</literal>
103
+ clause is not present, only rows that were successfully
98
104
inserted or updated will be returned. For example, if a row was
99
105
locked but not updated because an <literal>ON CONFLICT DO UPDATE
100
106
... WHERE</literal> clause <replaceable
101
107
class="parameter">condition</replaceable> was not satisfied, the
102
- row will not be returned.
108
+ row will not be returned. <literal>ON CONFLICT DO SELECT</literal>
109
+ works similarly, except no update takes place.
103
110
</para>
104
111
105
112
<para>
0 commit comments