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>RELEASE 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-reindex.html" title="REINDEX" /><link rel="next" href="sql-reset.html" title="RESET" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">RELEASE SAVEPOINT</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-reindex.html" title="REINDEX">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-reset.html" title="RESET">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-RELEASE-SAVEPOINT"><div class="titlepage"></div><a id="id-1.9.3.164.1" class="indexterm"></a><a id="id-1.9.3.164.2" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">RELEASE SAVEPOINT</span></h2><p>RELEASE SAVEPOINT — release a previously defined savepoint</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
3 RELEASE [ SAVEPOINT ] <em class="replaceable"><code>savepoint_name</code></em>
4 </pre></div><div class="refsect1" id="id-1.9.3.164.6"><h2>Description</h2><p>
5 <code class="command">RELEASE SAVEPOINT</code> releases the named savepoint and
6 all active savepoints that were created after the named savepoint,
7 and frees their resources. All changes made since the creation of
8 the savepoint that didn't already get rolled back are merged into
9 the transaction or savepoint that was active when the named savepoint
10 was created. Changes made after <code class="command">RELEASE SAVEPOINT</code>
11 will also be part of this active transaction or savepoint.
12 </p></div><div class="refsect1" id="id-1.9.3.164.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 name of the savepoint to release.
14 </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.164.8"><h2>Notes</h2><p>
15 Specifying a savepoint name that was not previously defined is an error.
17 It is not possible to release a savepoint when the transaction is in
18 an aborted state; to do that, use <a class="xref" href="sql-rollback-to.html" title="ROLLBACK TO SAVEPOINT"><span class="refentrytitle">ROLLBACK TO SAVEPOINT</span></a>.
20 If multiple savepoints have the same name, only the most recently defined
21 unreleased one is released. Repeated commands will release progressively
23 </p></div><div class="refsect1" id="id-1.9.3.164.9"><h2>Examples</h2><p>
24 To establish and later release a savepoint:
25 </p><pre class="programlisting">
27 INSERT INTO table1 VALUES (3);
28 SAVEPOINT my_savepoint;
29 INSERT INTO table1 VALUES (4);
30 RELEASE SAVEPOINT my_savepoint;
33 The above transaction will insert both 3 and 4.
35 A more complex example with multiple nested subtransactions:
36 </p><pre class="programlisting">
38 INSERT INTO table1 VALUES (1);
40 INSERT INTO table1 VALUES (2);
42 INSERT INTO table1 VALUES (3);
43 RELEASE SAVEPOINT sp2;
44 INSERT INTO table1 VALUES (4))); -- generates an error
46 In this example, the application requests the release of the savepoint
47 <code class="literal">sp2</code>, which inserted 3. This changes the insert's
48 transaction context to <code class="literal">sp1</code>. When the statement
49 attempting to insert value 4 generates an error, the insertion of 2 and
50 4 are lost because they are in the same, now-rolled back savepoint,
51 and value 3 is in the same transaction context. The application can
52 now only choose one of these two commands, since all other commands
54 </p><pre class="programlisting">
56 ROLLBACK TO SAVEPOINT sp1;
58 Choosing <code class="command">ROLLBACK</code> will abort everything, including
59 value 1, whereas <code class="command">ROLLBACK TO SAVEPOINT sp1</code> will retain
60 value 1 and allow the transaction to continue.
61 </p></div><div class="refsect1" id="id-1.9.3.164.10"><h2>Compatibility</h2><p>
62 This command conforms to the <acronym class="acronym">SQL</acronym> standard. The standard
63 specifies that the key word <code class="literal">SAVEPOINT</code> is
64 mandatory, but <span class="productname">PostgreSQL</span> allows it to
66 </p></div><div class="refsect1" id="id-1.9.3.164.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-rollback.html" title="ROLLBACK"><span class="refentrytitle">ROLLBACK</span></a>, <a class="xref" href="sql-rollback-to.html" title="ROLLBACK TO SAVEPOINT"><span class="refentrytitle">ROLLBACK TO SAVEPOINT</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-reindex.html" title="REINDEX">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-reset.html" title="RESET">Next</a></td></tr><tr><td width="40%" align="left" valign="top">REINDEX </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"> RESET</td></tr></table></div></body></html>