2004-08-01 19:32:22 +02:00
|
|
|
<!--
|
2010-09-20 22:08:53 +02:00
|
|
|
doc/src/sgml/ref/rollback_to.sgml
|
2004-08-01 19:32:22 +02:00
|
|
|
PostgreSQL documentation
|
|
|
|
-->
|
|
|
|
|
|
|
|
<refentry id="SQL-ROLLBACK-TO">
|
2014-02-24 03:25:35 +01:00
|
|
|
<indexterm zone="sql-rollback-to">
|
|
|
|
<primary>ROLLBACK TO SAVEPOINT</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="sql-rollback-to">
|
|
|
|
<primary>savepoints</primary>
|
|
|
|
<secondary>rolling back</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
2004-08-01 19:32:22 +02:00
|
|
|
<refmeta>
|
2010-04-03 09:23:02 +02:00
|
|
|
<refentrytitle>ROLLBACK TO SAVEPOINT</refentrytitle>
|
2008-11-14 11:22:48 +01:00
|
|
|
<manvolnum>7</manvolnum>
|
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>
|
|
|
|
|
|
|
|
<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>
|
2011-08-30 19:32:49 +02:00
|
|
|
Use <xref linkend="SQL-RELEASE-SAVEPOINT"> 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
|
2009-12-02 22:11:12 +01:00
|
|
|
affected by a <command>FETCH</> or <command>MOVE</> command inside a
|
|
|
|
savepoint that is later rolled back, the cursor remains at the
|
|
|
|
position that <command>FETCH</> left it pointing to (that is, the cursor
|
|
|
|
motion caused by <command>FETCH</> is not rolled back).
|
2005-01-27 00:20:21 +01:00
|
|
|
Closing a cursor is not undone by rolling back, either.
|
2009-12-02 22:11:12 +01:00
|
|
|
However, other side-effects caused by the cursor's query (such as
|
|
|
|
side-effects of volatile functions called by the query) <emphasis>are</>
|
|
|
|
rolled back if they occur during a savepoint that is later rolled back.
|
2004-08-01 19:32:22 +02:00
|
|
|
A cursor whose execution causes a transaction to abort is put in a
|
Wording cleanup for error messages. Also change can't -> cannot.
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
2007-02-01 20:10:30 +01:00
|
|
|
cannot-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;
|
2011-08-07 09:49:45 +02:00
|
|
|
</programlisting></para>
|
2004-08-01 19:32:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
</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">
|
2010-04-03 09:23:02 +02:00
|
|
|
<member><xref linkend="sql-begin"></member>
|
|
|
|
<member><xref linkend="sql-commit"></member>
|
|
|
|
<member><xref linkend="sql-release-savepoint"></member>
|
|
|
|
<member><xref linkend="sql-rollback"></member>
|
|
|
|
<member><xref linkend="sql-savepoint"></member>
|
2004-08-01 19:32:22 +02:00
|
|
|
</simplelist>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|