RELEASE SAVEPOINT

A transaction command for removing a previous savepoint

RELEASE SAVEPOINT is a transaction command for removing a previously defined savepoint.

RELEASE SAVEPOINT was added in PostgreSQL 8.0.

Usage

RELEASE SAVEPOINT removes a savepoint previously defined during a transaction. If there are other savepoints following the released savepoint, those will also be released.

Change history

Examples

Basic execution example for RELEASE SAVEPOINT:

postgres=# BEGIN;
BEGIN

postgres=*# INSERT INTO foo VALUES(1);
INSERT 0 1

postgres=*# SAVEPOINT s1;
SAVEPOINT

postgres=*# INSERT INTO foo VALUES(2);
INSERT 0 1

postgres=*# SAVEPOINT s2;
SAVEPOINT

postgres=*# INSERT INTO foo VALUES(3);
INSERT 0 1

postgres=*# RELEASE SAVEPOINT s2;
RELEASE

At this point, it is only possible to roll back to savepoint s1, or rollback the entire transaction:

postgres=*# ROLLBACK TO SAVEPOINT s2;
ERROR:  savepoint "s2" does not exist

postgres=!# ROLLBACK TO SAVEPOINT s1;
ROLLBACK

If savepoints exist after the released savepoint, these will also be released:

postgres=# BEGIN;
BEGIN

postgres=*# INSERT INTO foo VALUES(1);
INSERT 0 1

postgres=*# SAVEPOINT s1;
SAVEPOINT

postgres=*# INSERT INTO foo VALUES(2);
INSERT 0 1

postgres=*# SAVEPOINT s2;
SAVEPOINT

postgres=*# RELEASE SAVEPOINT s1;
RELEASE

postgres=*# ROLLBACK TO SAVEPOINT s2;
ERROR:  savepoint "s2" does not exist

Categories

SQL command, Transaction command, Transactions

See also

SAVEPOINT, ROLLBACK TO SAVEPOINT