ROLLBACK_TO_SAVEPOINT(7pg13)
β¨ ROLLBACK TO SAVEPOINT(7) β¨
okay bestie, welcome to the ROLLBACK_TO_SAVEPOINT(7) page from the PostgreSQL 13.23 Documentation. if your transaction is doing too much and you need to rewind to a savepoint, this is literally the main character command. π
π NAME π
ROLLBACK_TO_SAVEPOINT - roll back to a savepoint. that's the name, that's the vibe, and it ate. π
π SYNOPSIS π
ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name
π¦ DESCRIPTION π¦
okay so here's the tea: it rolls back all commands that were executed after the savepoint was established. the savepoint remains valid and can be rolled back to again later, if needed. no cap, that's iconic. β¨
ROLLBACK TO SAVEPOINT implicitly destroys all savepoints that were established after the named savepoint. not me nuking the later savepoints, but that's the vibe. π
πΈ PARAMETERS πΈ
savepoint_nameβ the savepoint to roll back to. that's it, that's the parameter, and it understood the assignment. π«Ά
π₯ NOTES π₯
- use
RELEASE SAVEPOINT(RELEASE_SAVEPOINT(7)) to destroy a savepoint without discarding the effects of commands executed after it was established. yep, different move, different slay. π - > π¨ specifying a savepoint name that has not been established is an error. no cap, bestie. π
- cursors have somewhat non-transactional behavior with respect to savepoints. any cursor that is opened inside a savepoint will be closed when the savepoint is rolled back. if a previously opened cursor is affected by a
FETCHorMOVEcommand inside a savepoint that is later rolled back, the cursor remains at the position thatFETCHleft it pointing to (that is, the cursor motion caused byFETCHis not rolled back). closing a cursor is not undone by rolling back, either. however, other side-effects caused by the cursor's query (such as side-effects of volatile functions called by the query) are rolled back if they occur during a savepoint that is later rolled back. a cursor whose execution causes a transaction to abort is put in a cannot-execute state, so while the transaction can be restored usingROLLBACK TO SAVEPOINT, the cursor can no longer be used. π
π EXAMPLES π
to undo the effects of the commands executed after my_savepoint was established:
ROLLBACK TO SAVEPOINT my_savepoint;
cursor positions are not affected by savepoint rollback β watch this little beauty:
BEGIN;
DECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2;
SAVEPOINT foo;
FETCH 1 FROM foo;
?column?
----------
1
ROLLBACK TO SAVEPOINT foo;
FETCH 1 FROM foo;
?column?
----------
2
COMMIT;
π COMPATIBILITY π
the SQL standard specifies that the key word SAVEPOINT is mandatory, but PostgreSQL and Oracle allow it to be omitted. SQL allows only WORK, not TRANSACTION, as a noise word after ROLLBACK. also, SQL has an optional clause AND [ NO ] CHAIN which is not currently supported by PostgreSQL. otherwise, this command conforms to the SQL standard. periodt. β
π¦ SEE ALSO π¦
BEGIN(7)COMMIT(7)RELEASE SAVEPOINT (RELEASE_SAVEPOINT(7))ROLLBACK(7)SAVEPOINT(7)
okay that's the page, ily, bye! π this one is from PostgreSQL 13.23, dated 2025, and it's literally the ROLLBACK TO SAVEPOINT(7) page. π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms