From ff8d68df5c5060ef4e86b747d07bbc19a1edafb8 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Sun, 8 Aug 2004 01:48:31 +0000 Subject: [PATCH] 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 --- doc/src/sgml/ref/begin.sgml | 5 ++++- doc/src/sgml/ref/update.sgml | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/src/sgml/ref/begin.sgml b/doc/src/sgml/ref/begin.sgml index d40cb416bc..bf1195f527 100644 --- a/doc/src/sgml/ref/begin.sgml +++ b/doc/src/sgml/ref/begin.sgml @@ -1,5 +1,5 @@ @@ -100,6 +100,9 @@ BEGIN [ WORK | TRANSACTION ] Issuing BEGIN when already inside a transaction block will provoke a warning message. The state of the transaction is not affected. + To nest transactions within a transaction block, use savepoints + (See + for more information). diff --git a/doc/src/sgml/ref/update.sgml b/doc/src/sgml/ref/update.sgml index 5695df1584..48d160b2ec 100644 --- a/doc/src/sgml/ref/update.sgml +++ b/doc/src/sgml/ref/update.sgml @@ -1,5 +1,5 @@ @@ -187,6 +187,19 @@ UPDATE employees SET sales_count = sales_count + 1 FROM accounts UPDATE employees SET sales_count = sales_count + 1 WHERE id = (SELECT sales_person FROM accounts WHERE name = 'Acme Corporation'); + + + 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. + +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; -- 2.40.0