public inbox for [email protected]  
help / color / mirror / Atom feed
From: David Fetter <[email protected]>
To: PostgreSQL Docs <[email protected]>
To: PostgreSQL Patches <[email protected]>
Subject: Example for UPDATE FROM with correllation
Date: Thu, 12 Jan 2006 14:17:27 -0800
Message-ID: <[email protected]> (raw)

Folks,

Please find enclosed a doc patch that adds an example of a correllated
UPDATE.

Cheers,
D
-- 
David Fetter [email protected] http://fetter.org/
phone: +1 415 235 3778

Remember to vote!

Index: doc/src/sgml/ref/update.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/ref/update.sgml,v
retrieving revision 1.33
diff -c -r1.33 update.sgml
*** doc/src/sgml/ref/update.sgml	12 Oct 2005 23:19:22 -0000	1.33
--- doc/src/sgml/ref/update.sgml	12 Jan 2006 22:04:40 -0000
***************
*** 213,218 ****
--- 213,230 ----
    (SELECT sales_person FROM accounts WHERE name = 'Acme Corporation');
  </programlisting>
  
+    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.
+ <programlisting>
+ 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;
+ </programlisting>
+ 
     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.


Attachments:

  [text/plain] correllated_update.diff (1.2K, 2-correllated_update.diff)
  download | inline diff:
Index: doc/src/sgml/ref/update.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/ref/update.sgml,v
retrieving revision 1.33
diff -c -r1.33 update.sgml
*** doc/src/sgml/ref/update.sgml	12 Oct 2005 23:19:22 -0000	1.33
--- doc/src/sgml/ref/update.sgml	12 Jan 2006 22:04:40 -0000
***************
*** 213,218 ****
--- 213,230 ----
    (SELECT sales_person FROM accounts WHERE name = 'Acme Corporation');
  </programlisting>
  
+    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.
+ <programlisting>
+ 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;
+ </programlisting>
+ 
     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.


view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Example for UPDATE FROM with correllation
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox