Commit a5836751 authored by Tom Lane's avatar Tom Lane

Allow optional SAVEPOINT keyword in RELEASE and ROLLBACK TO, for greater

compliance with SQL2003 spec syntax.

Oliver Jowett
parent 10249abf
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.60 2004/08/01 17:32:13 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.61 2004/08/12 19:12:21 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
Complete list of usable sgml source files in this directory. Complete list of usable sgml source files in this directory.
--> -->
...@@ -88,7 +88,7 @@ Complete list of usable sgml source files in this directory. ...@@ -88,7 +88,7 @@ Complete list of usable sgml source files in this directory.
<!entity notify system "notify.sgml"> <!entity notify system "notify.sgml">
<!entity prepare system "prepare.sgml"> <!entity prepare system "prepare.sgml">
<!entity reindex system "reindex.sgml"> <!entity reindex system "reindex.sgml">
<!entity releaseSavepoint system "release.sgml"> <!entity releaseSavepoint system "release_savepoint.sgml">
<!entity reset system "reset.sgml"> <!entity reset system "reset.sgml">
<!entity revoke system "revoke.sgml"> <!entity revoke system "revoke.sgml">
<!entity rollback system "rollback.sgml"> <!entity rollback system "rollback.sgml">
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/release.sgml,v 1.1 2004/08/01 17:32:13 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/release_savepoint.sgml,v 1.1 2004/08/12 19:12:21 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
<refentry id="SQL-RELEASE"> <refentry id="SQL-RELEASE-SAVEPOINT">
<refmeta> <refmeta>
<refentrytitle id="SQL-RELEASE-TITLE">RELEASE</refentrytitle> <refentrytitle id="SQL-RELEASE-SAVEPOINT-TITLE">RELEASE SAVEPOINT</refentrytitle>
<refmiscinfo>SQL - Language Statements</refmiscinfo> <refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta> </refmeta>
<refnamediv> <refnamediv>
<refname>RELEASE</refname> <refname>RELEASE SAVEPOINT</refname>
<refpurpose>destroy a previously defined savepoint</refpurpose> <refpurpose>destroy a previously defined savepoint</refpurpose>
</refnamediv> </refnamediv>
<indexterm zone="sql-release"> <indexterm zone="sql-release-savepoint">
<primary>RELEASE</primary> <primary>RELEASE SAVEPOINT</primary>
</indexterm> </indexterm>
<indexterm zone="sql-release"> <indexterm zone="sql-release-savepoint">
<primary>savepoints</primary> <primary>savepoints</primary>
<secondary>releasing</secondary> <secondary>releasing</secondary>
</indexterm> </indexterm>
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
RELEASE <replaceable>savepoint_name</replaceable> RELEASE [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
...@@ -33,7 +33,7 @@ RELEASE <replaceable>savepoint_name</replaceable> ...@@ -33,7 +33,7 @@ RELEASE <replaceable>savepoint_name</replaceable>
<title>Description</title> <title>Description</title>
<para> <para>
<command>RELEASE</command> destroys a savepoint previously defined <command>RELEASE SAVEPOINT</command> destroys a savepoint previously defined
in the current transaction. in the current transaction.
</para> </para>
...@@ -48,7 +48,7 @@ RELEASE <replaceable>savepoint_name</replaceable> ...@@ -48,7 +48,7 @@ RELEASE <replaceable>savepoint_name</replaceable>
</para> </para>
<para> <para>
<command>RELEASE</command> also destroys all savepoints that were <command>RELEASE SAVEPOINT</command> also destroys all savepoints that were
established after the named savepoint was established. established after the named savepoint was established.
</para> </para>
</refsect1> </refsect1>
...@@ -97,7 +97,7 @@ BEGIN; ...@@ -97,7 +97,7 @@ BEGIN;
INSERT INTO table VALUES (3); INSERT INTO table VALUES (3);
SAVEPOINT my_savepoint; SAVEPOINT my_savepoint;
INSERT INTO table VALUES (4); INSERT INTO table VALUES (4);
RELEASE my_savepoint; RELEASE SAVEPOINT my_savepoint;
COMMIT; COMMIT;
</programlisting> </programlisting>
The above transaction will insert both 3 and 4. The above transaction will insert both 3 and 4.
...@@ -108,7 +108,9 @@ COMMIT; ...@@ -108,7 +108,9 @@ COMMIT;
<title>Compatibility</title> <title>Compatibility</title>
<para> <para>
RELEASE is fully conforming to the SQL standard. The SQL2003 standard specifies that the keyword SAVEPOINT is mandatory.
<productname>PostgreSQL</productname> allows the SAVEPOINT keyword to be
omitted. Otherwise, this command is fully conforming.
</para> </para>
</refsect1> </refsect1>
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/rollback_to.sgml,v 1.1 2004/08/01 17:32:13 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/rollback_to.sgml,v 1.2 2004/08/12 19:12:21 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
<refentry id="SQL-ROLLBACK-TO"> <refentry id="SQL-ROLLBACK-TO">
<refmeta> <refmeta>
<refentrytitle id="SQL-ROLLBACK-TO-TITLE">ROLLBACK TO</refentrytitle> <refentrytitle id="SQL-ROLLBACK-TO-TITLE">ROLLBACK TO SAVEPOINT</refentrytitle>
<refmiscinfo>SQL - Language Statements</refmiscinfo> <refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta> </refmeta>
<refnamediv> <refnamediv>
<refname>ROLLBACK TO</refname> <refname>ROLLBACK TO SAVEPOINT</refname>
<refpurpose>roll back to a savepoint</refpurpose> <refpurpose>roll back to a savepoint</refpurpose>
</refnamediv> </refnamediv>
<indexterm zone="sql-rollback-to"> <indexterm zone="sql-rollback-to">
<primary>ROLLBACK TO</primary> <primary>ROLLBACK TO SAVEPOINT</primary>
</indexterm> </indexterm>
<indexterm zone="sql-rollback-to"> <indexterm zone="sql-rollback-to">
...@@ -25,7 +25,7 @@ PostgreSQL documentation ...@@ -25,7 +25,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ROLLBACK TO <replaceable>savepoint_name</replaceable> ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
...@@ -39,7 +39,7 @@ ROLLBACK TO <replaceable>savepoint_name</replaceable> ...@@ -39,7 +39,7 @@ ROLLBACK TO <replaceable>savepoint_name</replaceable>
</para> </para>
<para> <para>
<command>ROLLBACK TO</> implicitly destroys all savepoints that <command>ROLLBACK TO SAVEPOINT</> implicitly destroys all savepoints that
were established after the named savepoint. were established after the named savepoint.
</para> </para>
</refsect1> </refsect1>
...@@ -63,9 +63,9 @@ ROLLBACK TO <replaceable>savepoint_name</replaceable> ...@@ -63,9 +63,9 @@ ROLLBACK TO <replaceable>savepoint_name</replaceable>
<title>Notes</title> <title>Notes</title>
<para> <para>
Use <xref linkend="SQL-RELEASE" endterm="SQL-RELEASE-TITLE"> to Use <xref linkend="SQL-RELEASE-SAVEPOINT"
destroy a savepoint without discarding the effects of commands executed endterm="SQL-RELEASE-SAVEPOINT-TITLE"> to destroy a savepoint without
after it was established. discarding the effects of commands executed after it was established.
</para> </para>
<para> <para>
...@@ -81,7 +81,7 @@ ROLLBACK TO <replaceable>savepoint_name</replaceable> ...@@ -81,7 +81,7 @@ ROLLBACK TO <replaceable>savepoint_name</replaceable>
left it pointing to (that is, <command>FETCH</> is not rolled back). left it pointing to (that is, <command>FETCH</> is not rolled back).
A cursor whose execution causes a transaction to abort is put in a A cursor whose execution causes a transaction to abort is put in a
can't-execute state, so while the transaction can be restored using can't-execute state, so while the transaction can be restored using
<command>ROLLBACK TO</>, the cursor can no longer be used. <command>ROLLBACK TO SAVEPOINT</>, the cursor can no longer be used.
</para> </para>
</refsect1> </refsect1>
...@@ -92,7 +92,7 @@ ROLLBACK TO <replaceable>savepoint_name</replaceable> ...@@ -92,7 +92,7 @@ ROLLBACK TO <replaceable>savepoint_name</replaceable>
To undo the effects of the commands executed after <literal>my_savepoint</literal> To undo the effects of the commands executed after <literal>my_savepoint</literal>
was established: was established:
<programlisting> <programlisting>
ROLLBACK TO my_savepoint; ROLLBACK TO SAVEPOINT my_savepoint;
</programlisting> </programlisting>
</para> </para>
...@@ -110,7 +110,7 @@ FETCH 1 FROM foo; ...@@ -110,7 +110,7 @@ FETCH 1 FROM foo;
---------- ----------
1 1
ROLLBACK TO foo; ROLLBACK TO SAVEPOINT foo;
FETCH 1 FROM foo; FETCH 1 FROM foo;
?column? ?column?
...@@ -128,7 +128,13 @@ COMMIT; ...@@ -128,7 +128,13 @@ COMMIT;
<title>Compatibility</title> <title>Compatibility</title>
<para> <para>
This command is fully SQL standard conforming. The SQL2003 standard specifies that the keyword SAVEPOINT is mandatory.
<productname>PostgreSQL</productname> and <productname>Oracle</productname>
allow the SAVEPOINT keyword to be omitted. SQL2003 allows only
WORK, not TRANSACTION, as a noise word after ROLLBACK. Also, SQL2003
has an optional clause AND [ NO ] CHAIN which is not currently supported
by <productname>PostgreSQL</productname>. Otherwise, this command is
fully conforming.
</para> </para>
</refsect1> </refsect1>
...@@ -139,7 +145,7 @@ COMMIT; ...@@ -139,7 +145,7 @@ COMMIT;
<member><xref linkend="sql-begin" endterm="sql-begin-title"></member> <member><xref linkend="sql-begin" endterm="sql-begin-title"></member>
<member><xref linkend="sql-commit" endterm="sql-commit-title"></member> <member><xref linkend="sql-commit" endterm="sql-commit-title"></member>
<member><xref linkend="sql-savepoint" endterm="sql-savepoint-title"></member> <member><xref linkend="sql-savepoint" endterm="sql-savepoint-title"></member>
<member><xref linkend="sql-release" endterm="sql-release-title"></member> <member><xref linkend="sql-release-savepoint" endterm="sql-release-savepoint-title"></member>
<member><xref linkend="sql-rollback" endterm="sql-rollback-title"></member> <member><xref linkend="sql-rollback" endterm="sql-rollback-title"></member>
</simplelist> </simplelist>
</refsect1> </refsect1>
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/savepoint.sgml,v 1.1 2004/08/01 17:32:13 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/savepoint.sgml,v 1.2 2004/08/12 19:12:21 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -64,8 +64,8 @@ SAVEPOINT <replaceable>savepoint_name</replaceable> ...@@ -64,8 +64,8 @@ SAVEPOINT <replaceable>savepoint_name</replaceable>
<para> <para>
Use <xref linkend="SQL-ROLLBACK-TO" endterm="SQL-ROLLBACK-TO-TITLE"> to Use <xref linkend="SQL-ROLLBACK-TO" endterm="SQL-ROLLBACK-TO-TITLE"> to
rollback to a savepoint. Use <xref linkend="SQL-RELEASE" rollback to a savepoint. Use <xref linkend="SQL-RELEASE-SAVEPOINT"
endterm="SQL-RELEASE-TITLE"> to destroy a savepoint, keeping endterm="SQL-RELEASE-SAVEPOINT-TITLE"> to destroy a savepoint, keeping
the effects of commands executed after it was established. the effects of commands executed after it was established.
</para> </para>
...@@ -86,7 +86,7 @@ BEGIN; ...@@ -86,7 +86,7 @@ BEGIN;
INSERT INTO table VALUES (1); INSERT INTO table VALUES (1);
SAVEPOINT my_savepoint; SAVEPOINT my_savepoint;
INSERT INTO table VALUES (2); INSERT INTO table VALUES (2);
ROLLBACK TO my_savepoint; ROLLBACK TO SAVEPOINT my_savepoint;
INSERT INTO table VALUES (3); INSERT INTO table VALUES (3);
COMMIT; COMMIT;
</programlisting> </programlisting>
...@@ -100,7 +100,7 @@ BEGIN; ...@@ -100,7 +100,7 @@ BEGIN;
INSERT INTO table VALUES (3); INSERT INTO table VALUES (3);
SAVEPOINT my_savepoint; SAVEPOINT my_savepoint;
INSERT INTO table VALUES (4); INSERT INTO table VALUES (4);
RELEASE my_savepoint; RELEASE SAVEPOINT my_savepoint;
COMMIT; COMMIT;
</programlisting> </programlisting>
The above transaction will insert both 3 and 4. The above transaction will insert both 3 and 4.
...@@ -116,8 +116,8 @@ COMMIT; ...@@ -116,8 +116,8 @@ COMMIT;
<productname>PostgreSQL</>, the old savepoint is kept, though only the more <productname>PostgreSQL</>, the old savepoint is kept, though only the more
recent one will be used when rolling back or releasing. (Releasing the recent one will be used when rolling back or releasing. (Releasing the
newer savepoint will cause the older one to again become accessible to newer savepoint will cause the older one to again become accessible to
<command>ROLLBACK TO</> and <command>RELEASE</>.) <command>ROLLBACK TO SAVEPOINT</> and <command>RELEASE SAVEPOINT</>.)
Other than that, <command>SAVEPOINT</command> is fully SQL conforming. Otherwise, <command>SAVEPOINT</command> is fully SQL conforming.
</para> </para>
</refsect1> </refsect1>
...@@ -128,7 +128,7 @@ COMMIT; ...@@ -128,7 +128,7 @@ COMMIT;
<member><xref linkend="sql-begin" endterm="sql-begin-title"></member> <member><xref linkend="sql-begin" endterm="sql-begin-title"></member>
<member><xref linkend="sql-rollback" endterm="sql-rollback-title"></member> <member><xref linkend="sql-rollback" endterm="sql-rollback-title"></member>
<member><xref linkend="sql-rollback-to" endterm="sql-rollback-to-title"></member> <member><xref linkend="sql-rollback-to" endterm="sql-rollback-to-title"></member>
<member><xref linkend="sql-release" endterm="sql-release-title"></member> <member><xref linkend="sql-release-savepoint" endterm="sql-release-savepoint-title"></member>
<member><xref linkend="sql-commit" endterm="sql-commit-title"></member> <member><xref linkend="sql-commit" endterm="sql-commit-title"></member>
</simplelist> </simplelist>
</refsect1> </refsect1>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.469 2004/08/02 04:26:35 tgl Exp $ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.470 2004/08/12 19:12:21 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -3982,6 +3982,14 @@ TransactionStmt: ...@@ -3982,6 +3982,14 @@ TransactionStmt:
(Node *)makeString($2))); (Node *)makeString($2)));
$$ = (Node *)n; $$ = (Node *)n;
} }
| RELEASE SAVEPOINT ColId
{
TransactionStmt *n = makeNode(TransactionStmt);
n->kind = TRANS_STMT_RELEASE;
n->options = list_make1(makeDefElem("savepoint_name",
(Node *)makeString($3)));
$$ = (Node *)n;
}
| RELEASE ColId | RELEASE ColId
{ {
TransactionStmt *n = makeNode(TransactionStmt); TransactionStmt *n = makeNode(TransactionStmt);
...@@ -3990,12 +3998,20 @@ TransactionStmt: ...@@ -3990,12 +3998,20 @@ TransactionStmt:
(Node *)makeString($2))); (Node *)makeString($2)));
$$ = (Node *)n; $$ = (Node *)n;
} }
| ROLLBACK TO ColId | ROLLBACK opt_transaction TO SAVEPOINT ColId
{ {
TransactionStmt *n = makeNode(TransactionStmt); TransactionStmt *n = makeNode(TransactionStmt);
n->kind = TRANS_STMT_ROLLBACK_TO; n->kind = TRANS_STMT_ROLLBACK_TO;
n->options = list_make1(makeDefElem("savepoint_name", n->options = list_make1(makeDefElem("savepoint_name",
(Node *)makeString($3))); (Node *)makeString($5)));
$$ = (Node *)n;
}
| ROLLBACK opt_transaction TO ColId
{
TransactionStmt *n = makeNode(TransactionStmt);
n->kind = TRANS_STMT_ROLLBACK_TO;
n->options = list_make1(makeDefElem("savepoint_name",
(Node *)makeString($4)));
$$ = (Node *)n; $$ = (Node *)n;
} }
; ;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.223 2004/08/02 01:30:45 tgl Exp $ * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.224 2004/08/12 19:12:21 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -388,12 +388,12 @@ ProcessUtility(Node *parsetree, ...@@ -388,12 +388,12 @@ ProcessUtility(Node *parsetree,
break; break;
case TRANS_STMT_RELEASE: case TRANS_STMT_RELEASE:
RequireTransactionChain((void *)stmt, "RELEASE"); RequireTransactionChain((void *)stmt, "RELEASE SAVEPOINT");
ReleaseSavepoint(stmt->options); ReleaseSavepoint(stmt->options);
break; break;
case TRANS_STMT_ROLLBACK_TO: case TRANS_STMT_ROLLBACK_TO:
RequireTransactionChain((void *)stmt, "ROLLBACK TO"); RequireTransactionChain((void *)stmt, "ROLLBACK TO SAVEPOINT");
RollbackToSavepoint(stmt->options); RollbackToSavepoint(stmt->options);
/* /*
* CommitTransactionCommand is in charge * CommitTransactionCommand is in charge
......
...@@ -77,11 +77,11 @@ BEGIN; ...@@ -77,11 +77,11 @@ BEGIN;
SAVEPOINT one; SAVEPOINT one;
DROP TABLE foo; DROP TABLE foo;
CREATE TABLE bar (a int); CREATE TABLE bar (a int);
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
RELEASE one; RELEASE SAVEPOINT one;
SAVEPOINT two; SAVEPOINT two;
CREATE TABLE baz (a int); CREATE TABLE baz (a int);
RELEASE two; RELEASE SAVEPOINT two;
drop TABLE foobar; drop TABLE foobar;
CREATE TABLE barbaz (a int); CREATE TABLE barbaz (a int);
COMMIT; COMMIT;
...@@ -110,16 +110,16 @@ BEGIN; ...@@ -110,16 +110,16 @@ BEGIN;
INSERT into bar VALUES (1); INSERT into bar VALUES (1);
ERROR: relation "bar" does not exist ERROR: relation "bar" does not exist
ROLLBACK TO one; ROLLBACK TO one;
RELEASE one; RELEASE SAVEPOINT one;
SAVEPOINT two; SAVEPOINT two;
INSERT into barbaz VALUES (1); INSERT into barbaz VALUES (1);
RELEASE two; RELEASE two;
SAVEPOINT three; SAVEPOINT three;
SAVEPOINT four; SAVEPOINT four;
INSERT INTO foo VALUES (2); INSERT INTO foo VALUES (2);
RELEASE four; RELEASE SAVEPOINT four;
ROLLBACK TO three; ROLLBACK TO SAVEPOINT three;
RELEASE three; RELEASE SAVEPOINT three;
INSERT INTO foo VALUES (3); INSERT INTO foo VALUES (3);
COMMIT; COMMIT;
SELECT * FROM foo; -- should have 1 and 3 SELECT * FROM foo; -- should have 1 and 3
...@@ -140,8 +140,8 @@ BEGIN; ...@@ -140,8 +140,8 @@ BEGIN;
SAVEPOINT one; SAVEPOINT one;
SELECT foo; SELECT foo;
ERROR: column "foo" does not exist ERROR: column "foo" does not exist
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
RELEASE one; RELEASE SAVEPOINT one;
SAVEPOINT two; SAVEPOINT two;
CREATE TABLE savepoints (a int); CREATE TABLE savepoints (a int);
SAVEPOINT three; SAVEPOINT three;
...@@ -150,7 +150,7 @@ ERROR: column "foo" does not exist ...@@ -150,7 +150,7 @@ ERROR: column "foo" does not exist
INSERT INTO savepoints VALUES (2); INSERT INTO savepoints VALUES (2);
SAVEPOINT five; SAVEPOINT five;
INSERT INTO savepoints VALUES (3); INSERT INTO savepoints VALUES (3);
ROLLBACK TO five; ROLLBACK TO SAVEPOINT five;
COMMIT; COMMIT;
COMMIT; -- should not be in a transaction block COMMIT; -- should not be in a transaction block
WARNING: there is no transaction in progress WARNING: there is no transaction in progress
...@@ -165,7 +165,7 @@ SELECT * FROM savepoints; ...@@ -165,7 +165,7 @@ SELECT * FROM savepoints;
BEGIN; BEGIN;
SAVEPOINT one; SAVEPOINT one;
DELETE FROM savepoints WHERE a=1; DELETE FROM savepoints WHERE a=1;
RELEASE one; RELEASE SAVEPOINT one;
SAVEPOINT two; SAVEPOINT two;
DELETE FROM savepoints WHERE a=1; DELETE FROM savepoints WHERE a=1;
SAVEPOINT three; SAVEPOINT three;
...@@ -200,7 +200,7 @@ BEGIN; ...@@ -200,7 +200,7 @@ BEGIN;
INSERT INTO savepoints VALUES (6); INSERT INTO savepoints VALUES (6);
SAVEPOINT one; SAVEPOINT one;
INSERT INTO savepoints VALUES (7); INSERT INTO savepoints VALUES (7);
RELEASE one; RELEASE SAVEPOINT one;
INSERT INTO savepoints VALUES (8); INSERT INTO savepoints VALUES (8);
COMMIT; COMMIT;
-- rows 6 and 8 should have been created by the same xact -- rows 6 and 8 should have been created by the same xact
...@@ -221,7 +221,7 @@ BEGIN; ...@@ -221,7 +221,7 @@ BEGIN;
INSERT INTO savepoints VALUES (9); INSERT INTO savepoints VALUES (9);
SAVEPOINT one; SAVEPOINT one;
INSERT INTO savepoints VALUES (10); INSERT INTO savepoints VALUES (10);
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
INSERT INTO savepoints VALUES (11); INSERT INTO savepoints VALUES (11);
COMMIT; COMMIT;
SELECT a FROM savepoints WHERE a in (9, 10, 11); SELECT a FROM savepoints WHERE a in (9, 10, 11);
...@@ -244,7 +244,7 @@ BEGIN; ...@@ -244,7 +244,7 @@ BEGIN;
INSERT INTO savepoints VALUES (13); INSERT INTO savepoints VALUES (13);
SAVEPOINT two; SAVEPOINT two;
INSERT INTO savepoints VALUES (14); INSERT INTO savepoints VALUES (14);
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
INSERT INTO savepoints VALUES (15); INSERT INTO savepoints VALUES (15);
SAVEPOINT two; SAVEPOINT two;
INSERT INTO savepoints VALUES (16); INSERT INTO savepoints VALUES (16);
...@@ -266,9 +266,9 @@ BEGIN; ...@@ -266,9 +266,9 @@ BEGIN;
INSERT INTO savepoints VALUES (19); INSERT INTO savepoints VALUES (19);
SAVEPOINT two; SAVEPOINT two;
INSERT INTO savepoints VALUES (20); INSERT INTO savepoints VALUES (20);
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
INSERT INTO savepoints VALUES (21); INSERT INTO savepoints VALUES (21);
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
INSERT INTO savepoints VALUES (22); INSERT INTO savepoints VALUES (22);
COMMIT; COMMIT;
SELECT a FROM savepoints WHERE a BETWEEN 18 AND 22; SELECT a FROM savepoints WHERE a BETWEEN 18 AND 22;
...@@ -282,10 +282,10 @@ DROP TABLE savepoints; ...@@ -282,10 +282,10 @@ DROP TABLE savepoints;
-- only in a transaction block: -- only in a transaction block:
SAVEPOINT one; SAVEPOINT one;
ERROR: SAVEPOINT may only be used in transaction blocks ERROR: SAVEPOINT may only be used in transaction blocks
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
ERROR: ROLLBACK TO may only be used in transaction blocks ERROR: ROLLBACK TO SAVEPOINT may only be used in transaction blocks
RELEASE one; RELEASE SAVEPOINT one;
ERROR: RELEASE may only be used in transaction blocks ERROR: RELEASE SAVEPOINT may only be used in transaction blocks
-- Only "rollback to" allowed in aborted state -- Only "rollback to" allowed in aborted state
BEGIN; BEGIN;
SAVEPOINT one; SAVEPOINT one;
...@@ -293,9 +293,9 @@ BEGIN; ...@@ -293,9 +293,9 @@ BEGIN;
ERROR: division by zero ERROR: division by zero
SAVEPOINT two; -- ignored till the end of ... SAVEPOINT two; -- ignored till the end of ...
ERROR: current transaction is aborted, commands ignored until end of transaction block ERROR: current transaction is aborted, commands ignored until end of transaction block
RELEASE one; -- ignored till the end of ... RELEASE SAVEPOINT one; -- ignored till the end of ...
ERROR: current transaction is aborted, commands ignored until end of transaction block ERROR: current transaction is aborted, commands ignored until end of transaction block
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
SELECT 1; SELECT 1;
?column? ?column?
---------- ----------
...@@ -328,7 +328,7 @@ BEGIN; ...@@ -328,7 +328,7 @@ BEGIN;
9 9
(10 rows) (10 rows)
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
FETCH 10 FROM c; FETCH 10 FROM c;
unique2 unique2
--------- ---------
...@@ -344,7 +344,7 @@ BEGIN; ...@@ -344,7 +344,7 @@ BEGIN;
19 19
(10 rows) (10 rows)
RELEASE one; RELEASE SAVEPOINT one;
FETCH 10 FROM c; FETCH 10 FROM c;
unique2 unique2
--------- ---------
...@@ -365,12 +365,12 @@ BEGIN; ...@@ -365,12 +365,12 @@ BEGIN;
SAVEPOINT two; SAVEPOINT two;
FETCH 10 FROM c; FETCH 10 FROM c;
ERROR: division by zero ERROR: division by zero
ROLLBACK TO two; ROLLBACK TO SAVEPOINT two;
-- c is now dead to the world ... -- c is now dead to the world ...
FETCH 10 FROM c; FETCH 10 FROM c;
ERROR: portal "c" cannot be run ERROR: portal "c" cannot be run
ROLLBACK TO two; ROLLBACK TO SAVEPOINT two;
RELEASE two; RELEASE SAVEPOINT two;
FETCH 10 FROM c; FETCH 10 FROM c;
ERROR: portal "c" cannot be run ERROR: portal "c" cannot be run
COMMIT; COMMIT;
......
...@@ -64,11 +64,11 @@ BEGIN; ...@@ -64,11 +64,11 @@ BEGIN;
SAVEPOINT one; SAVEPOINT one;
DROP TABLE foo; DROP TABLE foo;
CREATE TABLE bar (a int); CREATE TABLE bar (a int);
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
RELEASE one; RELEASE SAVEPOINT one;
SAVEPOINT two; SAVEPOINT two;
CREATE TABLE baz (a int); CREATE TABLE baz (a int);
RELEASE two; RELEASE SAVEPOINT two;
drop TABLE foobar; drop TABLE foobar;
CREATE TABLE barbaz (a int); CREATE TABLE barbaz (a int);
COMMIT; COMMIT;
...@@ -84,16 +84,16 @@ BEGIN; ...@@ -84,16 +84,16 @@ BEGIN;
SAVEPOINT one; SAVEPOINT one;
INSERT into bar VALUES (1); INSERT into bar VALUES (1);
ROLLBACK TO one; ROLLBACK TO one;
RELEASE one; RELEASE SAVEPOINT one;
SAVEPOINT two; SAVEPOINT two;
INSERT into barbaz VALUES (1); INSERT into barbaz VALUES (1);
RELEASE two; RELEASE two;
SAVEPOINT three; SAVEPOINT three;
SAVEPOINT four; SAVEPOINT four;
INSERT INTO foo VALUES (2); INSERT INTO foo VALUES (2);
RELEASE four; RELEASE SAVEPOINT four;
ROLLBACK TO three; ROLLBACK TO SAVEPOINT three;
RELEASE three; RELEASE SAVEPOINT three;
INSERT INTO foo VALUES (3); INSERT INTO foo VALUES (3);
COMMIT; COMMIT;
SELECT * FROM foo; -- should have 1 and 3 SELECT * FROM foo; -- should have 1 and 3
...@@ -103,8 +103,8 @@ SELECT * FROM barbaz; -- should have 1 ...@@ -103,8 +103,8 @@ SELECT * FROM barbaz; -- should have 1
BEGIN; BEGIN;
SAVEPOINT one; SAVEPOINT one;
SELECT foo; SELECT foo;
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
RELEASE one; RELEASE SAVEPOINT one;
SAVEPOINT two; SAVEPOINT two;
CREATE TABLE savepoints (a int); CREATE TABLE savepoints (a int);
SAVEPOINT three; SAVEPOINT three;
...@@ -113,7 +113,7 @@ BEGIN; ...@@ -113,7 +113,7 @@ BEGIN;
INSERT INTO savepoints VALUES (2); INSERT INTO savepoints VALUES (2);
SAVEPOINT five; SAVEPOINT five;
INSERT INTO savepoints VALUES (3); INSERT INTO savepoints VALUES (3);
ROLLBACK TO five; ROLLBACK TO SAVEPOINT five;
COMMIT; COMMIT;
COMMIT; -- should not be in a transaction block COMMIT; -- should not be in a transaction block
SELECT * FROM savepoints; SELECT * FROM savepoints;
...@@ -122,7 +122,7 @@ SELECT * FROM savepoints; ...@@ -122,7 +122,7 @@ SELECT * FROM savepoints;
BEGIN; BEGIN;
SAVEPOINT one; SAVEPOINT one;
DELETE FROM savepoints WHERE a=1; DELETE FROM savepoints WHERE a=1;
RELEASE one; RELEASE SAVEPOINT one;
SAVEPOINT two; SAVEPOINT two;
DELETE FROM savepoints WHERE a=1; DELETE FROM savepoints WHERE a=1;
SAVEPOINT three; SAVEPOINT three;
...@@ -145,7 +145,7 @@ BEGIN; ...@@ -145,7 +145,7 @@ BEGIN;
INSERT INTO savepoints VALUES (6); INSERT INTO savepoints VALUES (6);
SAVEPOINT one; SAVEPOINT one;
INSERT INTO savepoints VALUES (7); INSERT INTO savepoints VALUES (7);
RELEASE one; RELEASE SAVEPOINT one;
INSERT INTO savepoints VALUES (8); INSERT INTO savepoints VALUES (8);
COMMIT; COMMIT;
-- rows 6 and 8 should have been created by the same xact -- rows 6 and 8 should have been created by the same xact
...@@ -157,7 +157,7 @@ BEGIN; ...@@ -157,7 +157,7 @@ BEGIN;
INSERT INTO savepoints VALUES (9); INSERT INTO savepoints VALUES (9);
SAVEPOINT one; SAVEPOINT one;
INSERT INTO savepoints VALUES (10); INSERT INTO savepoints VALUES (10);
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
INSERT INTO savepoints VALUES (11); INSERT INTO savepoints VALUES (11);
COMMIT; COMMIT;
SELECT a FROM savepoints WHERE a in (9, 10, 11); SELECT a FROM savepoints WHERE a in (9, 10, 11);
...@@ -170,7 +170,7 @@ BEGIN; ...@@ -170,7 +170,7 @@ BEGIN;
INSERT INTO savepoints VALUES (13); INSERT INTO savepoints VALUES (13);
SAVEPOINT two; SAVEPOINT two;
INSERT INTO savepoints VALUES (14); INSERT INTO savepoints VALUES (14);
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
INSERT INTO savepoints VALUES (15); INSERT INTO savepoints VALUES (15);
SAVEPOINT two; SAVEPOINT two;
INSERT INTO savepoints VALUES (16); INSERT INTO savepoints VALUES (16);
...@@ -185,9 +185,9 @@ BEGIN; ...@@ -185,9 +185,9 @@ BEGIN;
INSERT INTO savepoints VALUES (19); INSERT INTO savepoints VALUES (19);
SAVEPOINT two; SAVEPOINT two;
INSERT INTO savepoints VALUES (20); INSERT INTO savepoints VALUES (20);
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
INSERT INTO savepoints VALUES (21); INSERT INTO savepoints VALUES (21);
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
INSERT INTO savepoints VALUES (22); INSERT INTO savepoints VALUES (22);
COMMIT; COMMIT;
SELECT a FROM savepoints WHERE a BETWEEN 18 AND 22; SELECT a FROM savepoints WHERE a BETWEEN 18 AND 22;
...@@ -196,16 +196,16 @@ DROP TABLE savepoints; ...@@ -196,16 +196,16 @@ DROP TABLE savepoints;
-- only in a transaction block: -- only in a transaction block:
SAVEPOINT one; SAVEPOINT one;
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
RELEASE one; RELEASE SAVEPOINT one;
-- Only "rollback to" allowed in aborted state -- Only "rollback to" allowed in aborted state
BEGIN; BEGIN;
SAVEPOINT one; SAVEPOINT one;
SELECT 0/0; SELECT 0/0;
SAVEPOINT two; -- ignored till the end of ... SAVEPOINT two; -- ignored till the end of ...
RELEASE one; -- ignored till the end of ... RELEASE SAVEPOINT one; -- ignored till the end of ...
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
SELECT 1; SELECT 1;
COMMIT; COMMIT;
SELECT 1; -- this should work SELECT 1; -- this should work
...@@ -215,19 +215,19 @@ BEGIN; ...@@ -215,19 +215,19 @@ BEGIN;
DECLARE c CURSOR FOR SELECT unique2 FROM tenk1; DECLARE c CURSOR FOR SELECT unique2 FROM tenk1;
SAVEPOINT one; SAVEPOINT one;
FETCH 10 FROM c; FETCH 10 FROM c;
ROLLBACK TO one; ROLLBACK TO SAVEPOINT one;
FETCH 10 FROM c; FETCH 10 FROM c;
RELEASE one; RELEASE SAVEPOINT one;
FETCH 10 FROM c; FETCH 10 FROM c;
CLOSE c; CLOSE c;
DECLARE c CURSOR FOR SELECT unique2/0 FROM tenk1; DECLARE c CURSOR FOR SELECT unique2/0 FROM tenk1;
SAVEPOINT two; SAVEPOINT two;
FETCH 10 FROM c; FETCH 10 FROM c;
ROLLBACK TO two; ROLLBACK TO SAVEPOINT two;
-- c is now dead to the world ... -- c is now dead to the world ...
FETCH 10 FROM c; FETCH 10 FROM c;
ROLLBACK TO two; ROLLBACK TO SAVEPOINT two;
RELEASE two; RELEASE SAVEPOINT two;
FETCH 10 FROM c; FETCH 10 FROM c;
COMMIT; COMMIT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment