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.

Tom mentioned nested transactions being mentioned in places but I couldn't
find them (with grep). Suggestions?

Gavin
Index: doc/src/sgml/ref/begin.sgml
===================================================================
RCS file: /usr/local/cvsroot/pgsql-server/doc/src/sgml/ref/begin.sgml,v
retrieving revision 1.31
diff -2 -c -r1.31 begin.sgml
*** doc/src/sgml/ref/begin.sgml 1 Aug 2004 17:32:13 -0000       1.31
--- doc/src/sgml/ref/begin.sgml 6 Aug 2004 11:35:03 -0000
***************
*** 101,104 ****
--- 101,107 ----
     Issuing <command>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 <xref linkend="sql-start-transaction" endterm="sql-start-transaction-title">
+    for more information).
    </para>
   </refsect1>
Index: doc/src/sgml/ref/update.sgml
===================================================================
RCS file: /usr/local/cvsroot/pgsql-server/doc/src/sgml/ref/update.sgml,v
retrieving revision 1.29
diff -2 -c -r1.29 update.sgml
*** doc/src/sgml/ref/update.sgml        9 Jun 2004 19:08:13 -0000       1.29
--- doc/src/sgml/ref/update.sgml        6 Aug 2004 11:54:39 -0000
***************
*** 189,192 ****
--- 189,205 ----
    (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>
    </para>
   </refsect1>
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

               http://archives.postgresql.org

Reply via email to