2 .\" Title: RELEASE SAVEPOINT
3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "RELEASE SAVEPOINT" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 RELEASE_SAVEPOINT \- release a previously defined savepoint
35 RELEASE [ SAVEPOINT ] \fIsavepoint_name\fR
39 \fBRELEASE SAVEPOINT\fR
40 releases the named savepoint and all active savepoints that were created after the named savepoint, and frees their resources\&. All changes made since the creation of the savepoint that didn\*(Aqt already get rolled back are merged into the transaction or savepoint that was active when the named savepoint was created\&. Changes made after
41 \fBRELEASE SAVEPOINT\fR
42 will also be part of this active transaction or savepoint\&.
47 The name of the savepoint to release\&.
51 Specifying a savepoint name that was not previously defined is an error\&.
53 It is not possible to release a savepoint when the transaction is in an aborted state; to do that, use
54 ROLLBACK TO SAVEPOINT (\fBROLLBACK_TO_SAVEPOINT\fR(7))\&.
56 If multiple savepoints have the same name, only the most recently defined unreleased one is released\&. Repeated commands will release progressively older savepoints\&.
59 To establish and later release a savepoint:
66 INSERT INTO table1 VALUES (3);
67 SAVEPOINT my_savepoint;
68 INSERT INTO table1 VALUES (4);
69 RELEASE SAVEPOINT my_savepoint;
76 The above transaction will insert both 3 and 4\&.
78 A more complex example with multiple nested subtransactions:
85 INSERT INTO table1 VALUES (1);
87 INSERT INTO table1 VALUES (2);
89 INSERT INTO table1 VALUES (3);
90 RELEASE SAVEPOINT sp2;
91 INSERT INTO table1 VALUES (4))); \-\- generates an error
97 In this example, the application requests the release of the savepoint
98 sp2, which inserted 3\&. This changes the insert\*(Aqs transaction context to
99 sp1\&. When the statement attempting to insert value 4 generates an error, the insertion of 2 and 4 are lost because they are in the same, now\-rolled back savepoint, and value 3 is in the same transaction context\&. The application can now only choose one of these two commands, since all other commands will be ignored:
106 ROLLBACK TO SAVEPOINT sp1;
114 will abort everything, including value 1, whereas
115 \fBROLLBACK TO SAVEPOINT sp1\fR
116 will retain value 1 and allow the transaction to continue\&.
119 This command conforms to the
121 standard\&. The standard specifies that the key word
125 allows it to be omitted\&.
127 \fBBEGIN\fR(7), \fBCOMMIT\fR(7), \fBROLLBACK\fR(7), ROLLBACK TO SAVEPOINT (\fBROLLBACK_TO_SAVEPOINT\fR(7)), \fBSAVEPOINT\fR(7)