Skip to content

ROLLBACK

ROLLBACK undoes transaction-private work.

ROLLBACK [TRANSACTION]
ROLLBACK [TRANSACTION] TO [SAVEPOINT] savepoint_name

The plain form ends the transaction and discards all its work. ROLLBACK TO undoes only changes after the named savepoint and keeps the transaction and target savepoint active.

TRANSACTION and SAVEPOINT are optional words. Unquoted savepoint names are case-insensitive; quoted names preserve case.

Success returns an empty command result. The TO form leaves a transaction active; the plain form does not.

Use plain ROLLBACK before retrying an entire transaction after a serialization conflict, deadlock or row-lock timeout. Constraint errors remain explicitly rollback-capable in the verified TCP contract.

A plain rollback without a transaction, or a TO form without the named live savepoint, fails. Embedded, TCP and the 1.2 CLI route ROLLBACK TO through the active connection-local transaction.

ROLLBACK needs no object privilege of its own and cannot undo another connection’s transaction.

CREATE TABLE ref_rollback (id INTEGER PRIMARY KEY);
BEGIN;
INSERT INTO ref_rollback VALUES (1);
ROLLBACK;
SELECT id FROM ref_rollback;

See Transactions and Concurrency, SAVEPOINT and RELEASE SAVEPOINT.