↑↓ select↵ open⌫ change scopeOpen full search

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

Wiki / SQLSTATE

42P11 — Invalid cursor definition

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

English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

aliases
Unknown
class name
Syntax Error or Access Rule Violation
condition name
invalid_cursor_definition
lang
en
sqlstate
42P11

Definition PG 18

42P11 — Invalid cursor definition

At a glance {#at-a-glance}

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

Meaning {#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 {#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 {#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 {#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 {#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.

Related {#related}

Sources {#sources}

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

Compare versions

SQLSTATE evidence and recorded runtime versions

claims · identity.class-and-condition
{
  "claim_id": "identity.class-and-condition",
  "limits": "Identity does not enumerate all source branches or client failures.",
  "method": "Read fixed REL_18_6 errcodes.txt and locked facts.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.42P11.18.6"
  ],
  "statement": "42P11 is the invalid_cursor_definition condition in Class 42."
}
claims · mechanism.selected-source-path
{
  "claim_id": "mechanism.selected-source-path",
  "limits": "Representative confirmed core paths only; not exhaustive historical or extension coverage.",
  "method": "Read selected resolved REL_18_6 report groups and message roles.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.call.42P11.f167a76e45b0b00652025a79",
    "src.call.42P11.5f65e5c8b9b4ec55a8f821f9",
    "src.call.42P11.8742e1b79b2e47e0cf489b90"
  ],
  "statement": "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."
}
claims · versions.catalogue-boundary
{
  "claim_id": "versions.catalogue-boundary",
  "limits": "First observed release is a lower bound, not precise behavioral introduction.",
  "method": "Read locked catalogue facts and definition snapshot.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.42P11.18.6"
  ],
  "statement": "Locked catalogue snapshots show this condition by PostgreSQL 7.4; source behavior here is fixed at PostgreSQL 18.6."
}
messages · message.variant-1
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-1",
  "path": "",
  "position": 0,
  "raw": {
    "detail_templates": [],
    "hint_templates": [],
    "id": "message.variant-1",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "cannot open multi-query plan as cursor",
    "roles": [
      {
        "role": "errmsg",
        "template": "cannot open multi-query plan as cursor"
      }
    ],
    "severity_source": "ERROR",
    "sources": [
      "src.call.42P11.f167a76e45b0b00652025a79"
    ],
    "sqlstate": "42P11"
  },
  "severity": "ERROR",
  "sources": [
    "src.call.42P11.f167a76e45b0b00652025a79"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "cannot open multi-query plan as cursor",
      "position": 0,
      "role": "",
      "template": "cannot open multi-query plan as cursor"
    }
  ]
}
messages · message.variant-2
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-2",
  "path": "",
  "position": 1,
  "raw": {
    "detail_templates": [
      "Insensitive cursors must be READ ONLY."
    ],
    "hint_templates": [],
    "id": "message.variant-2",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "DECLARE INSENSITIVE CURSOR ... %s is not valid",
    "roles": [
      {
        "role": "errmsg",
        "template": "DECLARE INSENSITIVE CURSOR ... %s is not valid"
      },
      {
        "role": "errdetail",
        "template": "Insensitive cursors must be READ ONLY."
      }
    ],
    "severity_source": "ERROR",
    "sources": [
      "src.call.42P11.5f65e5c8b9b4ec55a8f821f9"
    ],
    "sqlstate": "42P11"
  },
  "severity": "ERROR",
  "sources": [
    "src.call.42P11.5f65e5c8b9b4ec55a8f821f9"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "DECLARE INSENSITIVE CURSOR ... is not valid",
      "position": 0,
      "role": "",
      "template": "DECLARE INSENSITIVE CURSOR ... %s is not valid"
    },
    {
      "kind": "detail",
      "literal": "Insensitive cursors must be READ ONLY.",
      "position": 1,
      "role": "",
      "template": "Insensitive cursors must be READ ONLY."
    },
    {
      "kind": "primary",
      "literal": "Insensitive cursors must be READ ONLY.",
      "position": 2,
      "role": "errdetail",
      "template": "Insensitive cursors must be READ ONLY."
    }
  ]
}
messages · message.variant-3
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-3",
  "path": "",
  "position": 2,
  "raw": {
    "detail_templates": [],
    "hint_templates": [],
    "id": "message.variant-3",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "cannot specify both %s and %s",
    "roles": [
      {
        "role": "errmsg",
        "template": "cannot specify both %s and %s"
      }
    ],
    "severity_source": "ERROR",
    "sources": [
      "src.call.42P11.8742e1b79b2e47e0cf489b90",
      "src.call.42P11.option-pair-asensitive"
    ],
    "sqlstate": "42P11"
  },
  "severity": "ERROR",
  "sources": [
    "src.call.42P11.8742e1b79b2e47e0cf489b90",
    "src.call.42P11.option-pair-asensitive"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "cannot specify both and",
      "position": 0,
      "role": "",
      "template": "cannot specify both %s and %s"
    }
  ]
}
sources · src.errcodes.42P11.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "line 392",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.42P11.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L392"
}
sources · src.call.42P11.f167a76e45b0b00652025a79
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 1600-1602",
  "path": "src/backend/executor/spi.c",
  "position": 1,
  "sha256": "7244b45f632583c72530832df901b788fe403c8857425dd13edb49d9f84b0c78",
  "source_id": "src.call.42P11.f167a76e45b0b00652025a79",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/spi.c#L1600-L1602"
}
sources · src.call.42P11.5f65e5c8b9b4ec55a8f821f9
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 3097-3104",
  "path": "src/backend/parser/analyze.c",
  "position": 2,
  "sha256": "98a23a176bbf95155d780b6512118999bc9fa68be8d88f0d013daf2a7512466a",
  "source_id": "src.call.42P11.5f65e5c8b9b4ec55a8f821f9",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/analyze.c#L3097-L3104"
}
sources · src.call.42P11.8742e1b79b2e47e0cf489b90
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 3040-3044",
  "path": "src/backend/parser/analyze.c",
  "position": 3,
  "sha256": "98a23a176bbf95155d780b6512118999bc9fa68be8d88f0d013daf2a7512466a",
  "source_id": "src.call.42P11.8742e1b79b2e47e0cf489b90",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/analyze.c#L3040-L3044"
}
sources · src.call.42P11.option-pair-asensitive
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 3048-3052",
  "path": "src/backend/parser/analyze.c",
  "position": 4,
  "sha256": "98a23a176bbf95155d780b6512118999bc9fa68be8d88f0d013daf2a7512466a",
  "source_id": "src.call.42P11.option-pair-asensitive",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/analyze.c#L3048-L3052"
}
sources · src.calls.REL_18_6.42P11
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "raw/calls/REL_18_6.jsonl",
  "position": 5,
  "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
  "source_id": "src.calls.REL_18_6.42P11",
  "tag": "",
  "url": ""
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:22a9290e3af3262e4b30f68867a56df48ef3644079aaa249642a232e5587a5d6

Text language: en · english-manuals:22a9290e3af3262e4b30f68867a56df48ef3644079aaa249642a232e5587a5d6