Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ff8d68d

Browse files
committed
Included is an example of using savepoints in a non-trivial example.
Giving examples in the SQL command reference is hard because we don't have conditionals at the SQL level. Gavin Sherry
1 parent 51fa8b0 commit ff8d68d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

doc/src/sgml/ref/begin.sgml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/begin.sgml,v 1.31 2004/08/01 17:32:13 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/begin.sgml,v 1.32 2004/08/08 01:48:31 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -100,6 +100,9 @@ BEGIN [ WORK | TRANSACTION ]
100100
<para>
101101
Issuing <command>BEGIN</> when already inside a transaction block will
102102
provoke a warning message. The state of the transaction is not affected.
103+
To nest transactions within a transaction block, use savepoints
104+
(See <xref linkend="sql-start-transaction" endterm="sql-start-transaction-title">
105+
for more information).
103106
</para>
104107
</refsect1>
105108

doc/src/sgml/ref/update.sgml

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/update.sgml,v 1.29 2004/06/09 19:08:13 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/update.sgml,v 1.30 2004/08/08 01:48:31 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -187,6 +187,19 @@ UPDATE employees SET sales_count = sales_count + 1 FROM accounts
187187
<programlisting>
188188
UPDATE employees SET sales_count = sales_count + 1 WHERE id =
189189
(SELECT sales_person FROM accounts WHERE name = 'Acme Corporation');
190+
</programlisting>
191+
192+
Attempt to insert a new stock item along with the quantity of stock. If
193+
the item exists, update the stock count of the existing item. To do this,
194+
use savepoints.
195+
<programlisting>
196+
BEGIN;
197+
SAVEPOINT sp1;
198+
INSERT INTO wines VALUES('Chateau Lafite 2003', '24');
199+
-- Check for unique violation on name
200+
ROLLBACK TO sp1;
201+
UPDATE wines SET stock = stock + 24 WHERE winename='Chateau Lafite 2003';
202+
COMMIT;
190203
</programlisting>
191204
</para>
192205
</refsect1>

0 commit comments

Comments
 (0)