Updated on 2025-10-23 GMT+08:00

ROLLBACK TO SAVEPOINT

Description

Rolls back to a savepoint. It implicitly destroys all savepoints that were established after the named savepoint.

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

Precautions

  • Rolling back to a savepoint name that has not been specified is an error.
  • Use ROLLBACK TO SAVEPOINT to roll back to a savepoint. Use RELEASE SAVEPOINT to destroy a savepoint but keep the effects of the commands executed after the savepoint was established.

Syntax

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

Parameters

  • savepoint_name

    Specifies the savepoint to roll back to.

Examples

-- Undo the effects of the statements executed after my_savepoint was established:
m_db=# START TRANSACTION;
m_db=# SAVEPOINT my_savepoint;
m_db=# ROLLBACK TO SAVEPOINT my_savepoint;
m_db=# RELEASE SAVEPOINT my_savepoint;
m_db=# COMMIT;

Helpful Links

SAVEPOINT and RELEASE SAVEPOINT