Savepoints in SQL
A savepoint is a transaction inside a transaction, so one step can fail alone.
BEGIN;
INSERT INTO tags (name)
VALUES ('imported');
SAVEPOINT risky_part;
UPDATE accounts
SET balance = balance - 100
WHERE id = 1;
ROLLBACK TO risky_part;
RELEASE risky_part;
COMMIT;
How it works
SAVEPOINT namemarks a point you can roll back to.ROLLBACK TO nameundoes the work since the mark and keeps the transaction.RELEASE nameaccepts that work and drops the mark.
Keywords and builtins used here
BEGINCOMMITINSERTINTOROLLBACKSETTOUPDATEVALUESWHERE
The run, in numbers
- Lines
- 16
- Characters to type
- 189
- Tokens
- 38
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 24 seconds.
Step 2 of 5 in Transactions, step 12 of 17 in Plans & performance.