From 40e151b70bf833ad022f1bdb37d3471ad2dfd985 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Thu, 19 Jan 2006 23:09:46 +0000 Subject: [PATCH] Doc patch that adds an example of a correllated UPDATE. David Fetter --- doc/src/sgml/ref/update.sgml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/doc/src/sgml/ref/update.sgml b/doc/src/sgml/ref/update.sgml index ac0495d0c2..72f2f2ecea 100644 --- a/doc/src/sgml/ref/update.sgml +++ b/doc/src/sgml/ref/update.sgml @@ -205,14 +205,32 @@ UPDATE employees SET sales_count = sales_count + 1 FROM accounts WHERE accounts.name = 'Acme Corporation' AND employees.id = accounts.sales_person; + + Perform the same operation, using a sub-select in the WHERE clause: UPDATE employees SET sales_count = sales_count + 1 WHERE id = (SELECT sales_person FROM accounts WHERE name = 'Acme Corporation'); + + + Now that all the papers are signed, update the most recently closed + deal of the travelling salesperson who closed the Rocket Powered + Skates deal with the Acme Corporation. + +UPDATE employees SET last_closed_deal = deal.id + FROM accounts JOIN deals ON (account.id = deal.account_id) + WHERE deal.employee_id = employees.id + AND deal.name = 'Rocket Powered Skates' + AND accounts.name = 'Acme Corporation' + ORDER BY deal.signed_date DESC LIMIT 1; + + + + Attempt to insert a new stock item along with the quantity of stock. If the item already exists, instead update the stock count of the existing item. To do this without failing the entire transaction, use savepoints. -- 2.39.5