Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd5d464

Browse files
committed
Doc patch that adds an example of a correllated UPDATE.
David Fetter
1 parent807cb00 commitcd5d464

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

‎doc/src/sgml/ref/update.sgml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/update.sgml,v 1.33 2005/10/12 23:19:22 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/update.sgml,v 1.34 2006/01/19 23:09:42 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -205,14 +205,32 @@ UPDATE employees SET sales_count = sales_count + 1 FROM accounts
205205
WHERE accounts.name = 'Acme Corporation'
206206
AND employees.id = accounts.sales_person;
207207
</programlisting>
208+
</para>
208209

210+
<para>
209211
Perform the same operation, using a sub-select in the
210212
<literal>WHERE</literal> clause:
211213
<programlisting>
212214
UPDATE employees SET sales_count = sales_count + 1 WHERE id =
213215
(SELECT sales_person FROM accounts WHERE name = 'Acme Corporation');
214216
</programlisting>
217+
</para>
215218

219+
<para>
220+
Now that all the papers are signed, update the most recently closed
221+
deal of the travelling salesperson who closed the Rocket Powered
222+
Skates deal with the Acme Corporation.
223+
<programlisting>
224+
UPDATE employees SET last_closed_deal = deal.id
225+
FROM accounts JOIN deals ON (account.id = deal.account_id)
226+
WHERE deal.employee_id = employees.id
227+
AND deal.name = 'Rocket Powered Skates'
228+
AND accounts.name = 'Acme Corporation'
229+
ORDER BY deal.signed_date DESC LIMIT 1;
230+
</programlisting>
231+
</para>
232+
233+
<para>
216234
Attempt to insert a new stock item along with the quantity of stock. If
217235
the item already exists, instead update the stock count of the existing
218236
item. To do this without failing the entire transaction, use savepoints.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp