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

EXAMPLES

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

COMPATIBILITY

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

SEE ALSO

80       BEGIN(7), COMMIT(7), RELEASE SAVEPOINT (RELEASE_SAVEPOINT(7)),
81       ROLLBACK(7), SAVEPOINT(7)
82
83
84
85PostgreSQL 13.3                      2021             ROLLBACK TO SAVEPOINT(7)
Impressum