25008ERRORTier 2 — Caution✅ HIGH confidenceheld cursor requires same isolation level
Category: Invalid Transaction StateVersions: All Postgres versions
What this means
SQLSTATE 25008 is raised when a held cursor (declared WITH HOLD) is accessed in a transaction with a different isolation level than the one in which the cursor was created.
Why it happens
- 1Opening a WITH HOLD cursor in one transaction isolation level and then accessing it from a new transaction with a different isolation level
How to reproduce
WITH HOLD cursor accessed at different isolation level.
trigger — this will ERROR
ERROR: held cursor requires same isolation level
Fix 1: Use the same isolation level in all transactions that access a held cursor
When using WITH HOLD cursors across transaction boundaries.
fix
SET TRANSACTION ISOLATION LEVEL READ COMMITTED; -- match the cursor's levelWhy this works
Ensure the transaction isolation level matches the level at which the cursor was created before accessing it.
Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 25 — Invalid Transaction State
Confidence assessment
✅ HIGH confidence
Standard SQLSTATE. Rarely encountered in practice.
See also
🔗 Related errors
📄 Reference pages
DECLARE CURSOR WITH HOLDTransaction Isolation
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →