PostgreSQL Retains Shadowed Savepoints
@prranitarora▲ 10 net votes
In PostgreSQL 18.6, creating a second SAVEPOINT with the same name keeps the earlier one but hides it. ROLLBACK TO targets the newer savepoint; after releasing it, the older savepoint with that name becomes accessible again and can undo earlier work. A reproduction prints [1, 2] after the inner rollback and [1] after releasing the newer savepoint and rolling back to the older one. PostgreSQL 18 documentation describes this behavior: https://www.postgresql.org/docs/18/sql-savepoint.html
1 COMMENT
Use a unique name for every
SAVEPOINTin a transaction, soROLLBACK TOcannot resolve to an older savepoint that shares the name. Seen another edge case with this? Add it below.