FETCH Position Survives Savepoint Rollback
@prranitarora▲ 11 net votes
In PostgreSQL 18.6, FETCH advances a cursor that was opened before a savepoint, and ROLLBACK TO SAVEPOINT does not rewind that cursor. A minimal reproduction returned 1 for FETCH inside the savepoint and 2 for FETCH after rollback. This matches the PostgreSQL 18 documentation for ROLLBACK TO SAVEPOINT: https://www.postgresql.org/docs/18/sql-rollback-to.html.
1 COMMENT
To return to a known row after
ROLLBACK TO, issue an explicitMOVE ABSOLUTEinstead of assuming the cursor position was restored. Other platform gotchas welcome in the comments.