]> begriffs open source - ai-pg/blob - full-docs/txt/sql-rollback-to.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / sql-rollback-to.txt
1
2 ROLLBACK TO SAVEPOINT
3
4    ROLLBACK TO SAVEPOINT — roll back to a savepoint
5
6 Synopsis
7
8 ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name
9
10 Description
11
12    Roll back all commands that were executed after the savepoint was
13    established and then start a new subtransaction at the same transaction
14    level. The savepoint remains valid and can be rolled back to again
15    later, if needed.
16
17    ROLLBACK TO SAVEPOINT implicitly destroys all savepoints that were
18    established after the named savepoint.
19
20 Parameters
21
22    savepoint_name
23           The savepoint to roll back to.
24
25 Notes
26
27    Use RELEASE SAVEPOINT to destroy a savepoint without discarding the
28    effects of commands executed after it was established.
29
30    Specifying a savepoint name that has not been established is an error.
31
32    Cursors have somewhat non-transactional behavior with respect to
33    savepoints. Any cursor that is opened inside a savepoint will be closed
34    when the savepoint is rolled back. If a previously opened cursor is
35    affected by a FETCH or MOVE command inside a savepoint that is later
36    rolled back, the cursor remains at the position that FETCH left it
37    pointing to (that is, the cursor motion caused by FETCH is not rolled
38    back). Closing a cursor is not undone by rolling back, either. However,
39    other side-effects caused by the cursor's query (such as side-effects
40    of volatile functions called by the query) are rolled back if they
41    occur during a savepoint that is later rolled back. A cursor whose
42    execution causes a transaction to abort is put in a cannot-execute
43    state, so while the transaction can be restored using ROLLBACK TO
44    SAVEPOINT, the cursor can no longer be used.
45
46 Examples
47
48    To undo the effects of the commands executed after my_savepoint was
49    established:
50 ROLLBACK TO SAVEPOINT my_savepoint;
51
52    Cursor positions are not affected by savepoint rollback:
53 BEGIN;
54
55 DECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;
56
57 SAVEPOINT foo;
58
59 FETCH 1 FROM foo;
60  ?column?
61 ----------
62         1
63
64 ROLLBACK TO SAVEPOINT foo;
65
66 FETCH 1 FROM foo;
67  ?column?
68 ----------
69         2
70
71 COMMIT;
72
73 Compatibility
74
75    The SQL standard specifies that the key word SAVEPOINT is mandatory,
76    but PostgreSQL and Oracle allow it to be omitted. SQL allows only WORK,
77    not TRANSACTION, as a noise word after ROLLBACK. Also, SQL has an
78    optional clause AND [ NO ] CHAIN which is not currently supported by
79    PostgreSQL. Otherwise, this command conforms to the SQL standard.
80
81 See Also
82
83    BEGIN, COMMIT, RELEASE SAVEPOINT, ROLLBACK, SAVEPOINT