2 .\" Title: ROLLBACK TO 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 "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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 ROLLBACK_TO_SAVEPOINT \- roll back to a savepoint
35 ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] \fIsavepoint_name\fR
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\&.
41 \fBROLLBACK TO SAVEPOINT\fR
42 implicitly destroys all savepoints that were established after the named savepoint\&.
47 The savepoint to roll back to\&.
52 \fBRELEASE SAVEPOINT\fR
53 to destroy a savepoint without discarding the effects of commands executed after it was established\&.
55 Specifying a savepoint name that has not been established is an error\&.
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
61 command inside a savepoint that is later rolled back, the cursor remains at the position that
63 left it pointing to (that is, the cursor motion caused by
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)
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\&.
71 To undo the effects of the commands executed after
79 ROLLBACK TO SAVEPOINT my_savepoint;
85 Cursor positions are not affected by savepoint rollback:
93 DECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;
102 ROLLBACK TO SAVEPOINT foo;
118 standard specifies that the key word
124 allow it to be omitted\&. SQL allows only
126 TRANSACTION, as a noise word after
127 ROLLBACK\&. Also, SQL has an optional clause
129 which is not currently supported by
130 PostgreSQL\&. Otherwise, this command conforms to the SQL standard\&.
132 \fBBEGIN\fR(7), \fBCOMMIT\fR(7), RELEASE SAVEPOINT (\fBRELEASE_SAVEPOINT\fR(7)), \fBROLLBACK\fR(7), \fBSAVEPOINT\fR(7)