@@ -21,7 +21,7 @@ PostgreSQL documentation
21
21
22
22
<refnamediv>
23
23
<refname>RELEASE SAVEPOINT</refname>
24
- <refpurpose>destroy a previously defined savepoint</refpurpose>
24
+ <refpurpose>release a previously defined savepoint</refpurpose>
25
25
</refnamediv>
26
26
27
27
<refsynopsisdiv>
@@ -34,23 +34,13 @@ RELEASE [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
34
34
<title>Description</title>
35
35
36
36
<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.
54
44
</para>
55
45
</refsect1>
56
46
@@ -62,7 +52,7 @@ RELEASE [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
62
52
<term><replaceable>savepoint_name</replaceable></term>
63
53
<listitem>
64
54
<para>
65
- The name of the savepoint to destroy .
55
+ The name of the savepoint to release .
66
56
</para>
67
57
</listitem>
68
58
</varlistentry>
@@ -78,7 +68,7 @@ RELEASE [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
78
68
79
69
<para>
80
70
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"/> .
82
72
</para>
83
73
84
74
<para>
@@ -93,7 +83,7 @@ RELEASE [ SAVEPOINT ] <replaceable>savepoint_name</replaceable>
93
83
<title>Examples</title>
94
84
95
85
<para>
96
- To establish and later destroy a savepoint:
86
+ To establish and later release a savepoint:
97
87
<programlisting>
98
88
BEGIN;
99
89
INSERT INTO table1 VALUES (3);
@@ -104,6 +94,36 @@ COMMIT;
104
94
</programlisting>
105
95
The above transaction will insert both 3 and 4.
106
96
</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
+
107
127
</refsect1>
108
128
109
129
<refsect1>
0 commit comments