]> begriffs open source - ai-pg/blob - full-docs/man7/ROLLBACK_TO_SAVEPOINT.7
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man7 / ROLLBACK_TO_SAVEPOINT.7
1 '\" t
2 .\"     Title: ROLLBACK TO 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 "ROLLBACK TO 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 ROLLBACK_TO_SAVEPOINT \- roll back to a savepoint
32 .SH "SYNOPSIS"
33 .sp
34 .nf
35 ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] \fIsavepoint_name\fR
36 .fi
37 .SH "DESCRIPTION"
38 .PP
39 Roll back all commands that were executed after the savepoint was established and then start a new subtransaction at the same transaction level\&. The savepoint remains valid and can be rolled back to again later, if needed\&.
40 .PP
41 \fBROLLBACK TO SAVEPOINT\fR
42 implicitly destroys all savepoints that were established after the named savepoint\&.
43 .SH "PARAMETERS"
44 .PP
45 \fIsavepoint_name\fR
46 .RS 4
47 The savepoint to roll back to\&.
48 .RE
49 .SH "NOTES"
50 .PP
51 Use
52 \fBRELEASE SAVEPOINT\fR
53 to destroy a savepoint without discarding the effects of commands executed after it was established\&.
54 .PP
55 Specifying a savepoint name that has not been established is an error\&.
56 .PP
57 Cursors have somewhat non\-transactional behavior with respect to savepoints\&. Any cursor that is opened inside a savepoint will be closed when the savepoint is rolled back\&. If a previously opened cursor is affected by a
58 \fBFETCH\fR
59 or
60 \fBMOVE\fR
61 command inside a savepoint that is later rolled back, the cursor remains at the position that
62 \fBFETCH\fR
63 left it pointing to (that is, the cursor motion caused by
64 \fBFETCH\fR
65 is not rolled back)\&. Closing a cursor is not undone by rolling back, either\&. However, other side\-effects caused by the cursor\*(Aqs query (such as side\-effects of volatile functions called by the query)
66 \fIare\fR
67 rolled back if they occur during a savepoint that is later rolled back\&. A cursor whose execution causes a transaction to abort is put in a cannot\-execute state, so while the transaction can be restored using
68 \fBROLLBACK TO SAVEPOINT\fR, the cursor can no longer be used\&.
69 .SH "EXAMPLES"
70 .PP
71 To undo the effects of the commands executed after
72 my_savepoint
73 was established:
74 .sp
75 .if n \{\
76 .RS 4
77 .\}
78 .nf
79 ROLLBACK TO SAVEPOINT my_savepoint;
80 .fi
81 .if n \{\
82 .RE
83 .\}
84 .PP
85 Cursor positions are not affected by savepoint rollback:
86 .sp
87 .if n \{\
88 .RS 4
89 .\}
90 .nf
91 BEGIN;
92
93 DECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;
94
95 SAVEPOINT foo;
96
97 FETCH 1 FROM foo;
98  ?column?
99 \-\-\-\-\-\-\-\-\-\-
100         1
101
102 ROLLBACK TO SAVEPOINT foo;
103
104 FETCH 1 FROM foo;
105  ?column?
106 \-\-\-\-\-\-\-\-\-\-
107         2
108
109 COMMIT;
110 .fi
111 .if n \{\
112 .RE
113 .\}
114 .SH "COMPATIBILITY"
115 .PP
116 The
117 SQL
118 standard specifies that the key word
119 SAVEPOINT
120 is mandatory, but
121 PostgreSQL
122 and
123 Oracle
124 allow it to be omitted\&. SQL allows only
125 WORK, not
126 TRANSACTION, as a noise word after
127 ROLLBACK\&. Also, SQL has an optional clause
128 AND [ NO ] CHAIN
129 which is not currently supported by
130 PostgreSQL\&. Otherwise, this command conforms to the SQL standard\&.
131 .SH "SEE ALSO"
132 \fBBEGIN\fR(7), \fBCOMMIT\fR(7), RELEASE SAVEPOINT (\fBRELEASE_SAVEPOINT\fR(7)), \fBROLLBACK\fR(7), \fBSAVEPOINT\fR(7)