aboutsummaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-04-08 10:54:03 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-04-08 10:54:03 -0400
commit8ad58279fa75636b776e4c648e1ffc7079a2c7d9 (patch)
tree9b7fe23de05483070e8f5f7438f72483d43a10ae /doc/src
parentb6bc481d5540a3ad0d39db1e9881e6bd52e54213 (diff)
downloadpostgresql-8ad58279fa75636b776e4c648e1ffc7079a2c7d9.tar.gz
postgresql-8ad58279fa75636b776e4c648e1ffc7079a2c7d9.zip
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.
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/ref/insert.sgml14
1 files changed, 14 insertions, 0 deletions
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
@@ -300,6 +300,20 @@ 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>
<refsect1>