ROLLBACK
ROLLBACK undoes transaction-private work.
Synopsis
Section titled “Synopsis”ROLLBACK [TRANSACTION]ROLLBACK [TRANSACTION] TO [SAVEPOINT] savepoint_nameDescription
Section titled “Description”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.
Parameters
Section titled “Parameters”TRANSACTION and SAVEPOINT are optional words. Unquoted savepoint names are case-insensitive; quoted names preserve case.
Result
Section titled “Result”Success returns an empty command result. The TO form leaves a transaction active; the plain form does not.
Transaction behavior
Section titled “Transaction behavior”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.
Errors and limitations
Section titled “Errors and limitations”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.
Privileges
Section titled “Privileges”ROLLBACK needs no object privilege of its own and cannot undo another connection’s transaction.
Example
Section titled “Example”CREATE TABLE ref_rollback (id INTEGER PRIMARY KEY);BEGIN;INSERT INTO ref_rollback VALUES (1);ROLLBACK;SELECT id FROM ref_rollback;See also
Section titled “See also”See Transactions and Concurrency, SAVEPOINT and RELEASE SAVEPOINT.