Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8ad5827

Browse files
committed
Add an example of WITH (UPDATE RETURNING) INSERT to the INSERT ref page.
Per a discussion with Gavin Flower. This barely scratches the surfaceof potential WITH (something RETURNING) use cases, of course, but it'sone of the simplest compelling examples I can think of.
1 parentb6bc481 commit8ad5827

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎doc/src/sgml/ref/insert.sgml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,20 @@ INSERT INTO tictactoe (game, board)
298298
<programlisting>
299299
INSERT INTO distributors (did, dname) VALUES (DEFAULT, 'XYZ Widgets')
300300
RETURNING did;
301+
</programlisting>
302+
</para>
303+
304+
<para>
305+
Increment the sales count of the salesperson who manages the
306+
account for Acme Corporation, and record the whole updated row
307+
along with current time in a log table:
308+
<programlisting>
309+
WITH upd AS (
310+
UPDATE employees SET sales_count = sales_count + 1 WHERE id =
311+
(SELECT sales_person FROM accounts WHERE name = 'Acme Corporation')
312+
RETURNING *
313+
)
314+
INSERT INTO employees_log SELECT *, current_timestamp FROM upd;
301315
</programlisting>
302316
</para>
303317
</refsect1>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp