postgres.git / summary / log / commit / refs

commit    8ad58279fa75636b776e4c648e1ffc7079a2c7d9
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Fri Apr 08 14:54:03 2011 +0000
First released in: 9.1.0

    Add an example of WITH (UPDATE RETURNING) INSERT to the INSERT ref page.
    
    Per a discussion with Gavin Flower.  This barely scratches the surface
    of potential WITH (something RETURNING) use cases, of course, but it's
    one of the simplest compelling examples I can think of.


doc/src/sgml/ref/insert.sgml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/src/sgml/ref/insert.sgml b/doc/src/sgml/ref/insert.sgml index 629cc7ea558..a5c0d5a0a68 100644 --- a/doc/src/sgml/ref/insert.sgml +++ b/doc/src/sgml/ref/insert.sgml @@ -298,6 +298,20 @@ INSERT INTO tictactoe (game, board) <programlisting> INSERT INTO distributors (did, dname) VALUES (DEFAULT, 'XYZ Widgets') RETURNING did; +</programlisting> + </para> + + <para> + Increment the sales count of the salesperson who manages the + account for Acme Corporation, and record the whole updated row + along with current time in a log table: +<programlisting> +WITH upd AS ( + UPDATE employees SET sales_count = sales_count + 1 WHERE id = + (SELECT sales_person FROM accounts WHERE name = 'Acme Corporation') + RETURNING * +) +INSERT INTO employees_log SELECT *, current_timestamp FROM upd; </programlisting> </para> </refsect1> [parent: b6bc481d5540]