Error 42P11 occurs when a DECLARE CURSOR statement mixes mutually exclusive clauses, such as WITH HOLD with FOR UPDATE/SHARE.
PostgreSQL Error 42P11 (invalid_cursor_definition) appears when a cursor is declared with incompatible options – most often WITH HOLD together with FOR UPDATE/SHARE. Remove the locking clause or drop WITH HOLD to resolve the error.
PostgreSQL Error 42P11
Error 42P11 signals that a DECLARE CURSOR statement is syntactically valid but semantically inconsistent. PostgreSQL rejects the cursor because its attributes or the underlying query violate cursor rules.
The error is classified under SQLSTATE class 42 (Syntax Error or Access Rule Violation). It usually blocks execution right after the DECLARE command.
The most common trigger is combining WITH HOLD with FOR UPDATE or FOR SHARE in the same cursor.
Holdable cursors survive COMMIT, but row-locking clauses cannot, so PostgreSQL raises 42P11.
Other causes include SCROLL restrictions, data-modifying CTEs inside the cursor query, and attempting to declare a cursor on a statement that does not return a simple result set.
Remove the conflicting clause. If the cursor must persist after COMMIT, drop FOR UPDATE/SHARE. If row locks are required, omit WITH HOLD and control the transaction manually.
For SCROLL problems, declare the cursor as NO SCROLL or remove positional fetches.
Always ensure the cursor query is a plain SELECT without data-modifying WITH queries.
Scenario: Reporting job opens a holdable cursor for a long-running export but mistakenly appends FOR UPDATE. Solution: strip the locking clause.
Scenario: Application declares SCROLL cursor on a CTE that updates rows. Solution: convert the CTE to a subquery and run the update separately.
Design cursors with a single purpose: scrolling, holding, or locking – never combine.
Keep cursor queries read-only.
Use Galaxy’s SQL linting to catch mixed clauses before execution. The editor flags WITH HOLD + FOR UPDATE combos instantly.
42P10 invalid_column_definition arises from illegal column defaults. 42P12 invalid_database_definition appears when CREATE DATABASE options conflict. Fix them by removing the contradictory clauses just as you would for 42P11.
.
No. PostgreSQL forbids the mix because row locks cannot persist after COMMIT, while WITH HOLD implies survival after commit.
The rule applies across all supported versions, though additional cursor checks were tightened in v14 and later.
Galaxy’s AI copilot parses DECLARE statements and warns about conflicting clauses before you run them, reducing trial-and-error debugging time.
Not always. SCROLL can inflate memory usage and fails on queries lacking unique ordering. Use NO SCROLL unless truly needed.