2004-08-01 19:32:22 +02:00
|
|
|
<!--
|
2006-09-16 02:30:20 +02:00
|
|
|
$PostgreSQL: pgsql/doc/src/sgml/ref/rollback_to.sgml,v 1.8 2006/09/16 00:30:20 momjian Exp $
|
2004-08-01 19:32:22 +02:00
|
|
|
PostgreSQL documentation
|
|
|
|
-->
|
|
|
|
|
|
|
|
<refentry id="SQL-ROLLBACK-TO">
|
|
|
|
<refmeta>
|
2004-08-12 21:12:21 +02:00
|
|
|
<refentrytitle id="SQL-ROLLBACK-TO-TITLE">ROLLBACK TO SAVEPOINT</refentrytitle>
|
2004-08-01 19:32:22 +02:00
|
|
|
<refmiscinfo>SQL - Language Statements</refmiscinfo>
|
|
|
|
</refmeta>
|
|
|
|
|
|
|
|
<refnamediv>
|
2004-08-12 21:12:21 +02:00
|
|
|
<refname>ROLLBACK TO SAVEPOINT</refname>
|
2004-08-01 19:32:22 +02:00
|
|
|
<refpurpose>roll back to a savepoint</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
<indexterm zone="sql-rollback-to">
|
2004-08-12 21:12:21 +02:00
|
|
|
<primary>ROLLBACK TO SAVEPOINT</primary>
|
2004-08-01 19:32:22 +02:00
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="sql-rollback-to">
|
|
|
|
<primary>savepoints</primary>
|
|
|
|
<secondary>rolling back</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<refsynopsisdiv>
|
|
|
|
<synopsis>
|
2004-08-12 21:12:21 +02:00
|
|
|
ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
|
2004-08-01 19:32:22 +02:00
|
|
|
</synopsis>
|
|
|
|
</refsynopsisdiv>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Roll back all commands that were executed after the savepoint was
|
|
|
|
established. The savepoint remains valid and can be rolled back to
|
|
|
|
again later, if needed.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2004-08-12 21:12:21 +02:00
|
|
|
<command>ROLLBACK TO SAVEPOINT</> implicitly destroys all savepoints that
|
2004-08-01 19:32:22 +02:00
|
|
|
were established after the named savepoint.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Parameters</title>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="PARAMETER">savepoint_name</></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The savepoint to roll back to.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Notes</title>
|
|
|
|
|
|
|
|
<para>
|
2004-08-12 21:12:21 +02:00
|
|
|
Use <xref linkend="SQL-RELEASE-SAVEPOINT"
|
|
|
|
endterm="SQL-RELEASE-SAVEPOINT-TITLE"> to destroy a savepoint without
|
|
|
|
discarding the effects of commands executed after it was established.
|
2004-08-01 19:32:22 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Specifying a savepoint name that has not been established is an error.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Cursors have somewhat non-transactional behavior with respect to
|
2005-01-27 00:20:21 +01:00
|
|
|
savepoints. Any cursor that is opened inside a savepoint will be closed
|
|
|
|
when the savepoint is rolled back. If a previously opened cursor is
|
|
|
|
affected by a
|
2004-08-01 19:32:22 +02:00
|
|
|
<command>FETCH</> command inside a savepoint that is later rolled
|
|
|
|
back, the cursor position remains at the position that <command>FETCH</>
|
|
|
|
left it pointing to (that is, <command>FETCH</> is not rolled back).
|
2005-01-27 00:20:21 +01:00
|
|
|
Closing a cursor is not undone by rolling back, either.
|
2004-08-01 19:32:22 +02:00
|
|
|
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
|
2004-08-12 21:12:21 +02:00
|
|
|
<command>ROLLBACK TO SAVEPOINT</>, the cursor can no longer be used.
|
2004-08-01 19:32:22 +02:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Examples</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
To undo the effects of the commands executed after <literal>my_savepoint</literal>
|
|
|
|
was established:
|
|
|
|
<programlisting>
|
2004-08-12 21:12:21 +02:00
|
|
|
ROLLBACK TO SAVEPOINT my_savepoint;
|
2004-08-01 19:32:22 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Cursor positions are not affected by savepoint rollback:
|
|
|
|
<programlisting>
|
|
|
|
BEGIN;
|
|
|
|
|
|
|
|
DECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;
|
|
|
|
|
|
|
|
SAVEPOINT foo;
|
|
|
|
|
|
|
|
FETCH 1 FROM foo;
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
1
|
|
|
|
|
2004-08-12 21:12:21 +02:00
|
|
|
ROLLBACK TO SAVEPOINT foo;
|
2004-08-01 19:32:22 +02:00
|
|
|
|
|
|
|
FETCH 1 FROM foo;
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
2
|
|
|
|
|
|
|
|
COMMIT;
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Compatibility</title>
|
|
|
|
|
|
|
|
<para>
|
2005-11-01 22:09:51 +01:00
|
|
|
The <acronym>SQL</> standard specifies that the key word
|
2004-11-27 22:27:08 +01:00
|
|
|
<literal>SAVEPOINT</> is mandatory, but <productname>PostgreSQL</>
|
2005-11-01 22:09:51 +01:00
|
|
|
and <productname>Oracle</> allow it to be omitted. SQL allows
|
2004-11-27 22:27:08 +01:00
|
|
|
only <literal>WORK</>, not <literal>TRANSACTION</>, as a noise word
|
2005-11-01 22:09:51 +01:00
|
|
|
after <literal>ROLLBACK</>. Also, SQL has an optional clause
|
2004-08-24 02:06:51 +02:00
|
|
|
<literal>AND [ NO ] CHAIN</> which is not currently supported by
|
2004-11-27 22:27:08 +01:00
|
|
|
<productname>PostgreSQL</>. Otherwise, this command conforms to
|
|
|
|
the SQL standard.
|
2004-08-01 19:32:22 +02:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>See Also</title>
|
|
|
|
|
|
|
|
<simplelist type="inline">
|
|
|
|
<member><xref linkend="sql-begin" endterm="sql-begin-title"></member>
|
|
|
|
<member><xref linkend="sql-commit" endterm="sql-commit-title"></member>
|
2004-08-12 21:12:21 +02:00
|
|
|
<member><xref linkend="sql-release-savepoint" endterm="sql-release-savepoint-title"></member>
|
2004-08-01 19:32:22 +02:00
|
|
|
<member><xref linkend="sql-rollback" endterm="sql-rollback-title"></member>
|
2004-09-20 02:04:19 +02:00
|
|
|
<member><xref linkend="sql-savepoint" endterm="sql-savepoint-title"></member>
|
2004-08-01 19:32:22 +02:00
|
|
|
</simplelist>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|