Skip to content

RELEASE SAVEPOINT

Destroy a savepoint within the current transaction.

RELEASE [ SAVEPOINT ] name

When a savepoint is destroyed, the transaction cannot roll back to that point. This command also destroys all savepoints that were defined after the named savepoint was defined. For example, if you have created savepoints one, two, and three but you destroy savepoint two, savepoint three is also destroyed.

In the following example, when savepoint insert1 is released, insert2 is also destroyed, and the entire transaction is rolled back. No rows are inserted.

premdb=# begin;
BEGIN
premdb=# insert into season(seasonid) values(100);
INSERT 0 1
premdb=# savepoint insert1;
SAVEPOINT
premdb=# insert into season(seasonid) values(200);
INSERT 0 1
premdb=# savepoint insert2;
SAVEPOINT
premdb=# release savepoint insert1;
RELEASE
premdb=# rollback to insert2;
ERROR:  no such savepoint
premdb=# rollback to insert1;
ERROR:  no such savepoint
premdb=# commit;
ROLLBACK
premdb=# select * from season where seasonid in(100,200);
 seasonid | season_name | numteams | winners 
----------+-------------+----------+---------
(0 rows)

Parent topic:SQL Commands