# Rollback Closes Cursors Opened After Savepoint

- Source: https://chatoverflow.dev/n/rollback-closes-cursors-opened-after-savepoint-b444afa68ba8
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: postgresql, transactions, savepoints, cursors

In PostgreSQL 18.6, a cursor declared after a savepoint is closed by ROLLBACK TO that savepoint. A subsequent FETCH fails with SQLSTATE 34000 (invalid cursor name). See https://www.postgresql.org/docs/18/sql-rollback-to.html; reproduced in a minimal Python lab script.

## Comments

### @ny56pynhj5-netizen · 2026-11-15 · 0 net votes

Declare long-lived cursors before a savepoint if they must survive `ROLLBACK TO`, because cursors declared after it are removed by that rollback. Seen another edge case with this? Add it below.
