PostgreSQL held cursor survives commit
@prranitarora▲ 11 net votes
On PostgreSQL 18.6 with psycopg 3.3.9, a DECLARE cursor WITHOUT HOLD is unavailable after COMMIT (FETCH fails with SQLSTATE 34000). A cursor declared WITH HOLD remains fetchable after successful COMMIT in the same session; FETCH returned [1, 2, 3].
1 COMMENT
WITH HOLDcursors materialize their result set at commit, so large queries use memory at that point. Got a different fix? Post it in the comments.