select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 42 · SYNTAX ERROR OR ACCESS RULE VIOLATION

invalid_cursor_definition

SQLSTATE
42P11
Condition name
invalid_cursor_definition
Class
Syntax Error or Access Rule Violation
Source macro
ERRCODE_INVALID_CURSOR_DEFINITION
Evidence
Source path confirmed
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>42P11 — Invalid cursor definition</h1>

At a glance

42P11 (invalid_cursor_definition) Cursor options and cursor plans have definition-time constraints.

Meaning

A cursor declaration or SPI cursor request violates a definition-time rule. Core 18.6 has separate paths for an SPI plan with more than one query, conflicting SCROLL/NO SCROLL or ASENSITIVE/INSENSITIVE options, and an INSENSITIVE cursor combined with a row-locking clause; the latter also reports that insensitive cursors must be READ ONLY.

Diagnosis

Preserve the exact option named by the error. Check whether the source is DECLARE or an SPI caller, whether the SPI plan contains more than one statement, and whether the option pair is SCROLL/NO SCROLL or ASENSITIVE/INSENSITIVE. For INSENSITIVE, inspect row-locking clauses and the required READ ONLY contract; do not diagnose this as a missing cursor.

Response

Split a multi-query SPI plan before opening a cursor, remove only the conflicting option, and add READ ONLY or remove the row lock when the INSENSITIVE contract requires it. If the caller is SPI, fix plan construction rather than changing cursor fetch code. An ERROR inside an explicit transaction requires ROLLBACK or ROLLBACK TO a pre-error savepoint before another command; autocommit can issue the corrected cursor request after the failed statement returns to idle.

Messages

Representative source messages include: message: cannot open multi-query plan as cursor; message: DECLARE INSENSITIVE CURSOR ... %s is not valid; DETAIL: Insensitive cursors must be READ ONLY.; message: cannot specify both %s and %s. Placeholders are filled by the actual object, column, or parameter.

Versions

The locked catalogue shows this condition by PostgreSQL 7.4; behavior here is fixed to PostgreSQL 18.6 source. Catalogue presence is a range boundary, not proof that every message or feature began in that release.

Sources

Source messages, line anchors, and evidence limits are recorded in authored evidence.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

42P11 is the invalid_cursor_definition condition in Class 42.

Method: Read fixed REL_18_6 errcodes.txt and locked facts.

Limits: Identity does not enumerate all source branches or client failures.

src.errcodes.42P11.18.6

Selected 18.6 paths separate an SPI plan with more than one query, conflicting SCROLL/NO SCROLL or ASENSITIVE/INSENSITIVE options, and an INSENSITIVE cursor combined with a row-locking clause; the latter reports that insensitive cursors must be READ ONLY.

Method: Read selected resolved REL_18_6 report groups and message roles.

Limits: Representative confirmed core paths only; not exhaustive historical or extension coverage.

src.call.42P11.f167a76e45b0b00652025a79 src.call.42P11.5f65e5c8b9b4ec55a8f821f9 src.call.42P11.8742e1b79b2e47e0cf489b90

Locked catalogue snapshots show this condition by PostgreSQL 7.4; source behavior here is fixed at PostgreSQL 18.6.

Method: Read locked catalogue facts and definition snapshot.

Limits: First observed release is a lower bound, not precise behavioral introduction.

src.errcodes.42P11.18.6

Message templates

ERROR · message.variant-1

Primary

cannot open multi-query plan as cursor

Placeholders remain dynamic source fields; no concrete runtime value is claimed.

ERROR · message.variant-2

Primary

DECLARE INSENSITIVE CURSOR ... %s is not valid

Detail

Insensitive cursors must be READ ONLY.

Primary

Insensitive cursors must be READ ONLY.

Placeholders remain dynamic source fields; no concrete runtime value is claimed.

ERROR · message.variant-3

Primary

cannot specify both %s and %s

Placeholders remain dynamic source fields; no concrete runtime value is claimed.

Reproduction & repair cases

No reproduction case is attached to this condition.

Recorded runtime evidence

No runtime observation is attached to this entry.

Definition snapshot: english-manuals:297f0b779e7117793988f205c9e… · English manual source