]> begriffs open source - ai-pg/blob - full-docs/man7/RELEASE_SAVEPOINT.7
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man7 / RELEASE_SAVEPOINT.7
1 '\" t
2 .\"     Title: RELEASE SAVEPOINT
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 RELEASE_SAVEPOINT \- release a previously defined savepoint
32 .SH "SYNOPSIS"
33 .sp
34 .nf
35 RELEASE [ SAVEPOINT ] \fIsavepoint_name\fR
36 .fi
37 .SH "DESCRIPTION"
38 .PP
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\&.
43 .SH "PARAMETERS"
44 .PP
45 \fIsavepoint_name\fR
46 .RS 4
47 The name of the savepoint to release\&.
48 .RE
49 .SH "NOTES"
50 .PP
51 Specifying a savepoint name that was not previously defined is an error\&.
52 .PP
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))\&.
55 .PP
56 If multiple savepoints have the same name, only the most recently defined unreleased one is released\&. Repeated commands will release progressively older savepoints\&.
57 .SH "EXAMPLES"
58 .PP
59 To establish and later release a savepoint:
60 .sp
61 .if n \{\
62 .RS 4
63 .\}
64 .nf
65 BEGIN;
66     INSERT INTO table1 VALUES (3);
67     SAVEPOINT my_savepoint;
68     INSERT INTO table1 VALUES (4);
69     RELEASE SAVEPOINT my_savepoint;
70 COMMIT;
71 .fi
72 .if n \{\
73 .RE
74 .\}
75 .sp
76 The above transaction will insert both 3 and 4\&.
77 .PP
78 A more complex example with multiple nested subtransactions:
79 .sp
80 .if n \{\
81 .RS 4
82 .\}
83 .nf
84 BEGIN;
85     INSERT INTO table1 VALUES (1);
86     SAVEPOINT sp1;
87     INSERT INTO table1 VALUES (2);
88     SAVEPOINT sp2;
89     INSERT INTO table1 VALUES (3);
90     RELEASE SAVEPOINT sp2;
91     INSERT INTO table1 VALUES (4))); \-\- generates an error
92 .fi
93 .if n \{\
94 .RE
95 .\}
96 .sp
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:
100 .sp
101 .if n \{\
102 .RS 4
103 .\}
104 .nf
105 ROLLBACK;
106 ROLLBACK TO SAVEPOINT sp1;
107 .fi
108 .if n \{\
109 .RE
110 .\}
111 .sp
112 Choosing
113 \fBROLLBACK\fR
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\&.
117 .SH "COMPATIBILITY"
118 .PP
119 This command conforms to the
120 SQL
121 standard\&. The standard specifies that the key word
122 SAVEPOINT
123 is mandatory, but
124 PostgreSQL
125 allows it to be omitted\&.
126 .SH "SEE ALSO"
127 \fBBEGIN\fR(7), \fBCOMMIT\fR(7), \fBROLLBACK\fR(7), ROLLBACK TO SAVEPOINT (\fBROLLBACK_TO_SAVEPOINT\fR(7)), \fBSAVEPOINT\fR(7)