@@ -21,7 +21,7 @@ PostgreSQL documentation
2121
2222 <refnamediv>
2323 <refname>RELEASE SAVEPOINT</refname>
24- <refpurpose>destroy a previously defined savepoint</refpurpose>
24+ <refpurpose>release a previously defined savepoint</refpurpose>
2525 </refnamediv>
2626
2727 <refsynopsisdiv>
@@ -34,23 +34,13 @@ RELEASE [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
3434 <title>Description</title>
3535
3636 <para>
37- <command>RELEASE SAVEPOINT</command> destroys a savepoint previously defined
38- in the current transaction.
39- </para>
40-
41- <para>
42- Destroying a savepoint makes it unavailable as a rollback point,
43- but it has no other user visible behavior. It does not undo the
44- effects of commands executed after the savepoint was established.
45- (To do that, see <xref linkend="sql-rollback-to"/>.)
46- Destroying a savepoint when
47- it is no longer needed allows the system to reclaim some resources
48- earlier than transaction end.
49- </para>
50-
51- <para>
52- <command>RELEASE SAVEPOINT</command> also destroys all savepoints that were
53- established after the named savepoint was established.
37+ <command>RELEASE SAVEPOINT</command> releases the named savepoint and
38+ all active savepoints that were created after the named savepoint,
39+ and frees their resources. All changes made since the creation of
40+ the savepoint that didn't already get rolled back are merged into
41+ the transaction or savepoint that was active when the named savepoint
42+ was created. Changes made after <command>RELEASE SAVEPOINT</command>
43+ will also be part of this active transaction or savepoint.
5444 </para>
5545 </refsect1>
5646
@@ -62,7 +52,7 @@ RELEASE [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
6252 <term><replaceable>savepoint_name</replaceable></term>
6353 <listitem>
6454 <para>
65- The name of the savepoint to destroy .
55+ The name of the savepoint to release .
6656 </para>
6757 </listitem>
6858 </varlistentry>
@@ -78,7 +68,7 @@ RELEASE [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
7868
7969 <para>
8070 It is not possible to release a savepoint when the transaction is in
81- an aborted state.
71+ an aborted state; to do that, use <xref linkend="sql-rollback-to"/> .
8272 </para>
8373
8474 <para>
@@ -93,7 +83,7 @@ RELEASE [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
9383 <title>Examples</title>
9484
9585 <para>
96- To establish and later destroy a savepoint:
86+ To establish and later release a savepoint:
9787<programlisting>
9888BEGIN;
9989 INSERT INTO table1 VALUES (3);
@@ -104,6 +94,36 @@ COMMIT;
10494</programlisting>
10595 The above transaction will insert both 3 and 4.
10696 </para>
97+
98+ <para>
99+ A more complex example with multiple nested subtransactions:
100+ <programlisting>
101+ BEGIN;
102+ INSERT INTO table1 VALUES (1);
103+ SAVEPOINT sp1;
104+ INSERT INTO table1 VALUES (2);
105+ SAVEPOINT sp2;
106+ INSERT INTO table1 VALUES (3);
107+ RELEASE SAVEPOINT sp2;
108+ INSERT INTO table1 VALUES (4))); -- generates an error
109+ </programlisting>
110+ In this example, the application requests the release of the savepoint
111+ <literal>sp2</literal>, which inserted 3. This changes the insert's
112+ transaction context to <literal>sp1</literal>. When the statement
113+ attempting to insert value 4 generates an error, the insertion of 2 and
114+ 4 are lost because they are in the same, now-rolled back savepoint,
115+ and value 3 is in the same transaction context. The application can
116+ now only choose one of these two commands, since all other commands
117+ will be ignored:
118+ <programlisting>
119+ ROLLBACK;
120+ ROLLBACK TO SAVEPOINT sp1;
121+ </programlisting>
122+ Choosing <command>ROLLBACK</command> will abort everything, including
123+ value 1, whereas <command>ROLLBACK TO SAVEPOINT sp1</command> will retain
124+ value 1 and allow the transaction to continue.
125+ </para>
126+
107127 </refsect1>
108128
109129 <refsect1>
0 commit comments