]> begriffs open source - ai-pg/blob - full-docs/html/sql-rollback-to.html
Include links to all subsection html pages, with shorter paths too
[ai-pg] / full-docs / html / sql-rollback-to.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>ROLLBACK TO SAVEPOINT</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="sql-rollback-prepared.html" title="ROLLBACK PREPARED" /><link rel="next" href="sql-savepoint.html" title="SAVEPOINT" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">ROLLBACK TO SAVEPOINT</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-rollback-prepared.html" title="ROLLBACK PREPARED">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-savepoint.html" title="SAVEPOINT">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-ROLLBACK-TO"><div class="titlepage"></div><a id="id-1.9.3.169.1" class="indexterm"></a><a id="id-1.9.3.169.2" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">ROLLBACK TO SAVEPOINT</span></h2><p>ROLLBACK TO SAVEPOINT — roll back to a savepoint</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
3 ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] <em class="replaceable"><code>savepoint_name</code></em>
4 </pre></div><div class="refsect1" id="id-1.9.3.169.6"><h2>Description</h2><p>
5    Roll back all commands that were executed after the savepoint was
6    established and then start a new subtransaction at the same transaction level.
7    The savepoint remains valid and can be rolled back to again later,
8    if needed.
9   </p><p>
10    <code class="command">ROLLBACK TO SAVEPOINT</code> implicitly destroys all savepoints that
11    were established after the named savepoint.
12   </p></div><div class="refsect1" id="id-1.9.3.169.7"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>savepoint_name</code></em></span></dt><dd><p>
13       The savepoint to roll back to.
14      </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.169.8"><h2>Notes</h2><p>
15    Use <a class="link" href="sql-release-savepoint.html" title="RELEASE SAVEPOINT"><code class="command">RELEASE SAVEPOINT</code></a> to destroy a savepoint
16    without discarding the effects of commands executed after it was
17    established.
18   </p><p>
19    Specifying a savepoint name that has not been established is an error.
20   </p><p>
21    Cursors have somewhat non-transactional behavior with respect to
22    savepoints.  Any cursor that is opened inside a savepoint will be closed
23    when the savepoint is rolled back.  If a previously opened cursor is
24    affected by a <code class="command">FETCH</code> or <code class="command">MOVE</code> command inside a
25    savepoint that is later rolled back, the cursor remains at the
26    position that <code class="command">FETCH</code> left it pointing to (that is, the cursor
27    motion caused by <code class="command">FETCH</code> is not rolled back).
28    Closing a cursor is not undone by rolling back, either.
29    However, other side-effects caused by the cursor's query (such as
30    side-effects of volatile functions called by the query) <span class="emphasis"><em>are</em></span>
31    rolled back if they occur during a savepoint that is later rolled back.
32    A cursor whose execution causes a transaction to abort is put in a
33    cannot-execute state, so while the transaction can be restored using
34    <code class="command">ROLLBACK TO SAVEPOINT</code>, the cursor can no longer be used.
35   </p></div><div class="refsect1" id="id-1.9.3.169.9"><h2>Examples</h2><p>
36    To undo the effects of the commands executed after <code class="literal">my_savepoint</code>
37    was established:
38 </p><pre class="programlisting">
39 ROLLBACK TO SAVEPOINT my_savepoint;
40 </pre><p>
41   </p><p>
42    Cursor positions are not affected by savepoint rollback:
43 </p><pre class="programlisting">
44 BEGIN;
45
46 DECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;
47
48 SAVEPOINT foo;
49
50 FETCH 1 FROM foo;
51  ?column?
52 ----------
53         1
54
55 ROLLBACK TO SAVEPOINT foo;
56
57 FETCH 1 FROM foo;
58  ?column?
59 ----------
60         2
61
62 COMMIT;
63 </pre></div><div class="refsect1" id="id-1.9.3.169.10"><h2>Compatibility</h2><p>
64    The <acronym class="acronym">SQL</acronym> standard specifies that the key word
65    <code class="literal">SAVEPOINT</code> is mandatory, but <span class="productname">PostgreSQL</span>
66    and <span class="productname">Oracle</span> allow it to be omitted.  SQL allows
67    only <code class="literal">WORK</code>, not <code class="literal">TRANSACTION</code>, as a noise word
68    after <code class="literal">ROLLBACK</code>.  Also, SQL has an optional clause
69    <code class="literal">AND [ NO ] CHAIN</code> which is not currently supported by
70    <span class="productname">PostgreSQL</span>.  Otherwise, this command conforms to
71    the SQL standard.
72   </p></div><div class="refsect1" id="id-1.9.3.169.11"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-begin.html" title="BEGIN"><span class="refentrytitle">BEGIN</span></a>, <a class="xref" href="sql-commit.html" title="COMMIT"><span class="refentrytitle">COMMIT</span></a>, <a class="xref" href="sql-release-savepoint.html" title="RELEASE SAVEPOINT"><span class="refentrytitle">RELEASE SAVEPOINT</span></a>, <a class="xref" href="sql-rollback.html" title="ROLLBACK"><span class="refentrytitle">ROLLBACK</span></a>, <a class="xref" href="sql-savepoint.html" title="SAVEPOINT"><span class="refentrytitle">SAVEPOINT</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-rollback-prepared.html" title="ROLLBACK PREPARED">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-savepoint.html" title="SAVEPOINT">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ROLLBACK PREPARED </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> SAVEPOINT</td></tr></table></div></body></html>