public inbox for [email protected]  
help / color / mirror / Atom feed
Example for UPDATE FROM with correllation
2+ messages / 2 participants
[nested] [flat]

* Example for UPDATE FROM with correllation
@ 2006-01-12 22:17  David Fetter <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: David Fetter @ 2006-01-12 22:17 UTC (permalink / raw)
  To: pgsql-docs; PostgreSQL Patches <[email protected]>

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.


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [PATCHES] Example for UPDATE FROM with correllation
@ 2006-01-19 23:10  Bruce Momjian <[email protected]>
  parent: David Fetter <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Bruce Momjian @ 2006-01-19 23:10 UTC (permalink / raw)
  To: David Fetter <[email protected]>; +Cc: pgsql-docs; PostgreSQL Patches <[email protected]>


Patch applied, with minor space adjustments to HEAD and 8.1.X.  I also
noticed a few earlier examples were missing paragraph formatting.

---------------------------------------------------------------------------

David Fetter wrote:
> 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!

[ Attachment, skipping... ]

> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
> 
>                http://archives.postgresql.org

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  [email protected]               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Index: doc/src/sgml/ref/update.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/ref/update.sgml,v
retrieving revision 1.33
diff -c -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	19 Jan 2006 23:08:08 -0000
***************
*** 205,218 ****
--- 205,236 ----
    WHERE accounts.name = 'Acme Corporation'
    AND employees.id = accounts.sales_person;
  </programlisting>
+   </para>
  
+   <para>
     Perform the same operation, using a sub-select in the
     <literal>WHERE</literal> clause:
  <programlisting>
  UPDATE employees SET sales_count = sales_count + 1 WHERE id =
    (SELECT sales_person FROM accounts WHERE name = 'Acme Corporation');
  </programlisting>
+   </para>
  
+   <para>
+    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>
+   </para>
+ 
+   <para>
     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] /bjm/diff (1.6K, 2-%2Fbjm%2Fdiff)
  download | inline:
Index: doc/src/sgml/ref/update.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/ref/update.sgml,v
retrieving revision 1.33
diff -c -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	19 Jan 2006 23:08:08 -0000
***************
*** 205,218 ****
--- 205,236 ----
    WHERE accounts.name = 'Acme Corporation'
    AND employees.id = accounts.sales_person;
  </programlisting>
+   </para>
  
+   <para>
     Perform the same operation, using a sub-select in the
     <literal>WHERE</literal> clause:
  <programlisting>
  UPDATE employees SET sales_count = sales_count + 1 WHERE id =
    (SELECT sales_person FROM accounts WHERE name = 'Acme Corporation');
  </programlisting>
+   </para>
  
+   <para>
+    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>
+   </para>
+ 
+   <para>
     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.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2006-01-19 23:10 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-01-12 22:17 Example for UPDATE FROM with correllation David Fetter <[email protected]>
2006-01-19 23:10 ` Bruce Momjian <[email protected]>

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