mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
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
This commit is contained in:
parent
51fa8b0120
commit
ff8d68df5c
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/begin.sgml,v 1.31 2004/08/01 17:32:13 tgl Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/begin.sgml,v 1.32 2004/08/08 01:48:31 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -100,6 +100,9 @@ BEGIN [ WORK | TRANSACTION ]
|
|||||||
<para>
|
<para>
|
||||||
Issuing <command>BEGIN</> when already inside a transaction block will
|
Issuing <command>BEGIN</> when already inside a transaction block will
|
||||||
provoke a warning message. The state of the transaction is not affected.
|
provoke a warning message. The state of the transaction is not affected.
|
||||||
|
To nest transactions within a transaction block, use savepoints
|
||||||
|
(See <xref linkend="sql-start-transaction" endterm="sql-start-transaction-title">
|
||||||
|
for more information).
|
||||||
</para>
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/update.sgml,v 1.29 2004/06/09 19:08:13 tgl Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/update.sgml,v 1.30 2004/08/08 01:48:31 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -187,6 +187,19 @@ UPDATE employees SET sales_count = sales_count + 1 FROM accounts
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
UPDATE employees SET sales_count = sales_count + 1 WHERE id =
|
UPDATE employees SET sales_count = sales_count + 1 WHERE id =
|
||||||
(SELECT sales_person FROM accounts WHERE name = 'Acme Corporation');
|
(SELECT sales_person FROM accounts WHERE name = 'Acme Corporation');
|
||||||
|
</programlisting>
|
||||||
|
|
||||||
|
Attempt to insert a new stock item along with the quantity of stock. If
|
||||||
|
the item exists, update the stock count of the existing item. To do this,
|
||||||
|
use savepoints.
|
||||||
|
<programlisting>
|
||||||
|
BEGIN;
|
||||||
|
SAVEPOINT sp1;
|
||||||
|
INSERT INTO wines VALUES('Chateau Lafite 2003', '24');
|
||||||
|
-- Check for unique violation on name
|
||||||
|
ROLLBACK TO sp1;
|
||||||
|
UPDATE wines SET stock = stock + 24 WHERE winename='Chateau Lafite 2003';
|
||||||
|
COMMIT;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user