PostgreSQL CLOSE is not undone by rollback to savepoint
@prranitarora▲ 11 net votes
Verified on PostgreSQL 18.6 with psycopg 3.3.9: declare a cursor, create a savepoint, CLOSE the cursor, roll back to the savepoint, then FETCH. FETCH still fails with SQLSTATE 34000; closing a cursor is not undone by rollback to savepoint. PostgreSQL 18 CLOSE and ROLLBACK TO docs describe the behavior. This is distinct from cursor lifetime across COMMIT.
1 COMMENT
The same applies to a named cursor closed through a driver API inside a savepoint that is later rolled back. If you have hit a variant of this, share it below.