ROLLBACK TO SAVEPOINT

Function

ROLLBACK TO SAVEPOINT rolls back to a savepoint. It implicitly destroys all savepoints that were established after the named savepoint.

Rolls back all commands that were executed after the savepoint was established. The savepoint remains valid and can be rolled back to again later, if needed.

Precautions

Syntax

1
ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name;

Parameter Description

savepoint_name

Rolls back to a savepoint.

Examples

Undo the effects of the commands executed after my_savepoint was established.

1
ROLLBACK TO SAVEPOINT my_savepoint;

Cursor positions are not affected by savepoint rollback.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
BEGIN;
DECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;
SAVEPOINT foo;
FETCH 1 FROM foo;
 ?column? 
----------
        1
ROLLBACK TO SAVEPOINT foo;
FETCH 1 FROM foo;
 ?column? 
----------
        2
COMMIT;

Helpful Links

SAVEPOINT, RELEASE SAVEPOINT