选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / 错误代码 / Class 42 语法错误或访问规则冲突

42P11 invalid_cursor_definition

无效游标定义

ERROR 源码确认 参考 未实测

条件名
invalid_cursor_definition
宏名称
ERRCODE_INVALID_CURSOR_DEFINITION
启用版本
7.4
状态
活跃

版本覆盖

速览

42P11invalid_cursor_definition)游标选项和游标计划在定义阶段有明确约束。

含义

游标声明或 SPI 游标请求违反了定义阶段的规则。18.6 核心分别处理包含多个查询的 SPI 计划、互相冲突的 SCROLL/NO SCROLLASENSITIVE/INSENSITIVE 选项,以及 INSENSITIVE 游标与行锁子句同时出现的情况;后一种路径还会说明 INSENSITIVE 游标必须是 READ ONLY。

诊断

保留错误中点名的选项。确认来源是 DECLARE 还是 SPI 调用者,SPI 计划是否含多个语句,以及冲突的是 SCROLL/NO SCROLL 还是 ASENSITIVE/INSENSITIVE。对于 INSENSITIVE,还要检查行锁子句和 READ ONLY 契约;不要把它误诊为游标不存在。

处理

打开游标前拆分多查询 SPI 计划,只删除冲突选项;INSENSITIVE 需要只读时加上 READ ONLY 或移除行锁。若调用者使用 SPI,应修复计划构造,而不是改动游标提取逻辑。显式事务中的 ERROR 之后,下一条命令前要 ROLLBACK 或回滚到错误前的保存点;自动提交模式下连接可在返回空闲后重发修正请求。

消息

固定源码中的代表性消息包括: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。占位符由实际对象、列或参数填充。

报文模板

源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。

主消息 cannot open multi-query plan as cursor

来源:src/backend/executor/spi.c(lines 1600-1602) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 DECLARE INSENSITIVE CURSOR ... %s is not valid
DETAIL Insensitive cursors must be READ ONLY.
主消息 · errdetail Insensitive cursors must be READ ONLY.

来源:src/backend/parser/analyze.c(lines 3097-3104) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 cannot specify both %s and %s

来源:src/backend/parser/analyze.c(lines 3040-3044) @ REL_18_6 · src/backend/parser/analyze.c(lines 3048-3052) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

版本

锁定目录显示该条件最早见于 PostgreSQL 7.4;行为说明固定在 PostgreSQL 18.6 源码,目录存在范围不等于每条消息或功能都从该版本开始。

来源

证据

断言

每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。

  • 42P11 is the invalid_cursor_definition condition in Class 42.

    核实方式Read fixed REL_18_6 errcodes.txt and locked facts.

    不覆盖Identity does not enumerate all source branches or client failures.

    来源src/backend/utils/errcodes.txt(line 392)

  • 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.

    核实方式Read selected resolved REL_18_6 report groups and message roles.

    不覆盖Representative confirmed core paths only; not exhaustive historical or extension coverage.

    来源src/backend/executor/spi.c(lines 1600-1602) · src/backend/parser/analyze.c(lines 3097-3104) · src/backend/parser/analyze.c(lines 3040-3044)

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

    核实方式Read locked catalogue facts and definition snapshot.

    不覆盖First observed release is a lower bound, not precise behavioral introduction.

    来源src/backend/utils/errcodes.txt(line 392)

同类错误代码

Class 42 语法错误或访问规则冲突 下的其他成员。