42P11 — 无效游标定义
游标声明违反定义阶段规则,如 SCROLL 选项冲突。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Syntax Error or Access Rule Violation
- condition name
- invalid_cursor_definition
- lang
- en
- sqlstate
- 42P11
版本定义 PG 18
42P11 — 无效游标定义
速览 {#at-a-glance}
42P11(invalid_cursor_definition)游标选项和游标计划在定义阶段有明确约束。
含义 {#meaning}
游标声明或 SPI 游标请求违反了定义阶段的规则。18.6 核心分别处理包含多个查询的 SPI 计划、互相冲突的 SCROLL/NO SCROLL 或 ASENSITIVE/INSENSITIVE 选项,以及 INSENSITIVE 游标与行锁子句同时出现的情况;后一种路径还会说明 INSENSITIVE 游标必须是 READ ONLY。
诊断 {#diagnosis}
保留错误中点名的选项。确认来源是 DECLARE 还是 SPI 调用者,SPI 计划是否含多个语句,以及冲突的是 SCROLL/NO SCROLL 还是 ASENSITIVE/INSENSITIVE。对于 INSENSITIVE,还要检查行锁子句和 READ ONLY 契约;不要把它误诊为游标不存在。
处理 {#response}
打开游标前拆分多查询 SPI 计划,只删除冲突选项;INSENSITIVE 需要只读时加上 READ ONLY 或移除行锁。若调用者使用 SPI,应修复计划构造,而不是改动游标提取逻辑。显式事务中的 ERROR 之后,下一条命令前要 ROLLBACK 或回滚到错误前的保存点;自动提交模式下连接可在返回空闲后重发修正请求。
消息 {#messages}
固定源码中的代表性消息包括: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。占位符由实际对象、列或参数填充。
版本 {#versions}
锁定目录显示该条件最早见于 PostgreSQL 7.4;行为说明固定在 PostgreSQL 18.6 源码,目录存在范围不等于每条消息或功能都从该版本开始。
相关 {#related}
来源 {#sources}
源码消息、行号和证据边界见 作者证据。
src/backend/executor/spi.c:1600-1602(fixed source)src/backend/parser/analyze.c:3097-3104(fixed source)src/backend/parser/analyze.c:3040-3044(fixed source)src/backend/parser/analyze.c:3048-3052(fixed source)
比较版本
SQLSTATE 证据与已记录的运行版本
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": ""
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:22a9290e3af3262e4b30f68867a56df48ef3644079aaa249642a232e5587a5d6
正文语言: zh-Hans · english-manuals:22a9290e3af3262e4b30f68867a56df48ef3644079aaa249642a232e5587a5d6