The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/14/sql-savepoint.html
Description:

The "Compatibility" section deserves some code example to illustrate the
behavior when reusing the same savepoint name.

Maybe this could help:

CREATE TABLE tab1 ( pk INT, name VARCHAR(50) );
BEGIN;
INSERT INTO tab1 VALUES (101,'aaa');
SAVEPOINT mysp; /* mysp #1 */
UPDATE tab1 SET name = 'bbb' WHERE pk = 101;
SAVEPOINT mysp; /* mysp #2 */
UPDATE tab1 SET name = 'ccc' WHERE pk = 101;
ROLLBACK TO SAVEPOINT mysp; /* rolls back to mysp #2 */
SELECT * FROM tab1 ORDER BY pk;
RELEASE SAVEPOINT mysp; /* releases mysp #2 */
ROLLBACK TO SAVEPOINT mysp; /* rolls back to mysp #1 */
SELECT * FROM tab1 ORDER BY pk;
COMMIT;
DROP TABLE tab1;

First SELECT will show 101/bbb, second will show 101/aaa ....

Reply via email to