SAVEPOINT(7)
π SAVEPOINT(7) π
okay so bestie, welcome to the SAVEPOINT page from the PostgreSQL 16.15 Documentation β this is the manual page literally called SAVEPOINT(7) and it's about to make your transaction game iconic. β¨
π NAME π
SAVEPOINT β define a new savepoint within the current transaction. that's it. that's the whole vibe. π
β¨ SYNOPSIS β¨
SAVEPOINT savepoint_name
π¦ DESCRIPTION π¦
SAVEPOINT establishes a new savepoint within the current transaction. periodt. π«Ά
A savepoint is a special mark inside a transaction that lets you roll back all the commands executed after it was established β restoring the transaction state to exactly what it was at the time of the savepoint. it's giving undo button but make it SQL. no cap. π
πΈ PARAMETERS πΈ
savepoint_nameβ the name you're giving to the new savepoint. and listen π if savepoints with the same name already exist, they will be inaccessible until the newer identically-named savepoints are released. iykyk.
π NOTES π
- use
ROLLBACK TOto rollback to a savepoint. π₯ - use
RELEASE SAVEPOINTto destroy a savepoint β and it keeps the effects of the commands executed after it was established. bestie it's non-destructive, slay. π
Savepoints can only be established when you're inside a transaction block. and yes, there can be multiple savepoints defined within a transaction. you can stack them. iconic behaviour honestly. π
π EXAMPLES π
π§ establish a savepoint and later undo the effects
to establish a savepoint and later undo the effects of all commands executed after it was established:
BEGIN;
INSERT INTO table1 VALUES (1);
SAVEPOINT my_savepoint;
INSERT INTO table1 VALUES (2);
ROLLBACK TO SAVEPOINT my_savepoint;
INSERT INTO table1 VALUES (3);
COMMIT;
the above transaction will insert the values 1 and 3, but not 2. the way that 2 justβ¦ didn't happen ππ
π§ establish and later destroy a savepoint
to establish and later destroy a savepoint:
BEGIN;
INSERT INTO table1 VALUES (3);
SAVEPOINT my_savepoint;
INSERT INTO table1 VALUES (4);
RELEASE SAVEPOINT my_savepoint;
COMMIT;
the above transaction will insert both 3 and 4. we love a release that keeps everything π«Άβ¨
π§ use a single savepoint name
to use a single savepoint name:
BEGIN;
INSERT INTO table1 VALUES (1);
SAVEPOINT my_savepoint;
INSERT INTO table1 VALUES (2);
SAVEPOINT my_savepoint;
INSERT INTO table1 VALUES (3);
-- rollback to the second savepoint
ROLLBACK TO SAVEPOINT my_savepoint;
SELECT * FROM table1; -- shows rows 1 and 2
-- release the second savepoint
RELEASE SAVEPOINT my_savepoint;
-- rollback to the first savepoint
ROLLBACK TO SAVEPOINT my_savepoint;
SELECT * FROM table1; -- shows only row 1
COMMIT;
the above transaction shows row 3 being rolled back first, then row 2. the nesting?? the drama?? main character energy. π
β COMPATIBILITY β
okay so this is the part where we're slightly β¨differentβ¨ from the standard, ngl:
- SQL requires a savepoint to be destroyed automatically when another savepoint with the same name is established.
- in PostgreSQL, the old savepoint is kept β though only the more recent one will be used when rolling back or releasing. (releasing the newer savepoint with
RELEASE SAVEPOINTwill cause the older one to again become accessible toROLLBACK TO SAVEPOINTandRELEASE SAVEPOINT.)
otherwise, SAVEPOINT is fully SQL conforming. so mostly a good girl fr fr π
π« SEE ALSO π«
BEGIN(7)COMMIT(7)RELEASE SAVEPOINT(RELEASE_SAVEPOINT(7))ROLLBACK(7)ROLLBACK TO SAVEPOINT(ROLLBACK_TO_SAVEPOINT(7))
and that's the whole page bestie!! π¦π this was PostgreSQL 16.15, dated 2026 β go forth and savepoint responsibly, mwah π ππΈ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-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