1ROLLBACK TO SAVEPOINT(7) PostgreSQL 14.3 DocumentationROLLBACK TO SAVEPOINT(7)
2
3
4

NAME

6       ROLLBACK_TO_SAVEPOINT - roll back to a savepoint
7

SYNOPSIS

9       ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name
10

DESCRIPTION

12       Roll back all commands that were executed after the savepoint was
13       established. The savepoint remains valid and can be rolled back to
14       again later, if needed.
15
16       ROLLBACK TO SAVEPOINT implicitly destroys all savepoints that were
17       established after the named savepoint.
18

PARAMETERS

20       savepoint_name
21           The savepoint to roll back to.
22

NOTES

24       Use RELEASE SAVEPOINT to destroy a savepoint without discarding the
25       effects of commands executed after it was established.
26
27       Specifying a savepoint name that has not been established is an error.
28
29       Cursors have somewhat non-transactional behavior with respect to
30       savepoints. Any cursor that is opened inside a savepoint will be closed
31       when the savepoint is rolled back. If a previously opened cursor is
32       affected by a FETCH or MOVE command inside a savepoint that is later
33       rolled back, the cursor remains at the position that FETCH left it
34       pointing to (that is, the cursor motion caused by FETCH is not rolled
35       back). Closing a cursor is not undone by rolling back, either. However,
36       other side-effects caused by the cursor's query (such as side-effects
37       of volatile functions called by the query) are rolled back if they
38       occur during a savepoint that is later rolled back. A cursor whose
39       execution causes a transaction to abort is put in a cannot-execute
40       state, so while the transaction can be restored using ROLLBACK TO
41       SAVEPOINT, the cursor can no longer be used.
42

EXAMPLES

44       To undo the effects of the commands executed after my_savepoint was
45       established:
46
47           ROLLBACK TO SAVEPOINT my_savepoint;
48
49       Cursor positions are not affected by savepoint rollback:
50
51           BEGIN;
52
53           DECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;
54
55           SAVEPOINT foo;
56
57           FETCH 1 FROM foo;
58            ?column?
59           ----------
60                   1
61
62           ROLLBACK TO SAVEPOINT foo;
63
64           FETCH 1 FROM foo;
65            ?column?
66           ----------
67                   2
68
69           COMMIT;
70

COMPATIBILITY

72       The SQL standard specifies that the key word SAVEPOINT is mandatory,
73       but PostgreSQL and Oracle allow it to be omitted. SQL allows only WORK,
74       not TRANSACTION, as a noise word after ROLLBACK. Also, SQL has an
75       optional clause AND [ NO ] CHAIN which is not currently supported by
76       PostgreSQL. Otherwise, this command conforms to the SQL standard.
77

SEE ALSO

79       BEGIN(7), COMMIT(7), RELEASE SAVEPOINT (RELEASE_SAVEPOINT(7)),
80       ROLLBACK(7), SAVEPOINT(7)
81
82
83
84PostgreSQL 14.3                      2022             ROLLBACK TO SAVEPOINT(7)
Impressum