百科 / 错误代码 / Class 42 语法错误或访问规则冲突
42P03 duplicate_cursor
重复游标
ERROR 源码确认 详解 未实测
- 条件名
duplicate_cursor- 宏名称
ERRCODE_DUPLICATE_CURSOR- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
42P03(duplicate_cursor)报告游标或 portal 名称冲突,但同一 SQLSTATE 覆盖 ERROR、替换时的 WARNING,以及 PL/pgSQL 活动游标的 ERROR。调用方和 CreatePortal 选项决定具体行为。
含义
CreatePortal(name, allowDup, dupSilent) 在 allowDup 为 false 时报告 ERROR cursor "%s" already exists。allowDup 为 true 时,若 dupSilent 未设置,会先发 WARNING closing existing cursor "%s",随后删除旧 portal 并创建新 portal。PL/pgSQL 是另一条路径:SPI_cursor_find 发现同名活动游标时报告 ERROR cursor "%s" already in use。
诊断
记录准确名称、来源(SQL portal 创建还是 PL/pgSQL OPEN)、严重性和事务状态。SQL 路径检查 portal 创建/复用及适用时的 pg_cursors;PL/pgSQL 路径检查游标变量和 OPEN/CLOSE 流程。allowDup 的替换分支不能推出所有重复声明都会 WARNING,PL/pgSQL 分支也不是 portal 管理器的替换路径。
处理
非替换 portal 路径报 ERROR 时,关闭旧 portal 或使用符合事务生命周期的新名称。WARNING 替换路径已经关闭旧 portal,应用仍应确认替换是预期行为。PL/pgSQL 应在重新打开前关闭命名游标,或使用不同变量/名称。只有 ERROR 路径需要通过回滚保存点或回滚事务恢复显式事务;重连不能替代查清连接池所有权。
消息变体
18.6 代表报文如下:
| 路径 | 严重性 | 主消息 |
|---|---|---|
CreatePortal(..., allowDup=false, ...) |
ERROR |
cursor "%s" already exists |
CreatePortal(..., allowDup=true, dupSilent=false) |
WARNING |
closing existing cursor "%s" |
| 已找到 PL/pgSQL 命名游标 | ERROR |
cursor "%s" already in use |
%s 为动态游标名称,本页不声称具体名称。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
cursor "%s" already exists
来源:src/backend/utils/mmgr/portalmem.c(lines 185-187) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
closing existing cursor "%s"
来源:src/backend/utils/mmgr/portalmem.c(lines 189-192) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
cursor "%s" already in use
来源:src/pl/plpgsql/src/pl_exec.c(lines 2895-2897) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
版本
目录范围从 7.4 到 18.6、19beta3,不是精确的功能引入判断。选定的是 18.6 固定 portal 管理器和 PL/pgSQL 源码路径,未运行数据库。
来源
- 上游源码 src/pl/plpgsql/src/pl_exec.c 第 2895–2897 行
- 上游源码 src/backend/utils/mmgr/portalmem.c 第 189–192 行
- 上游源码 src/backend/utils/mmgr/portalmem.c 第 185–187 行
- 上游源码 src/backend/utils/errcodes.txt 第 378 行
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
42P03 is the duplicate_cursor condition in Class 42.
-
CreatePortal(name, allowDup, dupSilent) reports ERROR `cursor "%s" already exists` when allowDup is false, can report WARNING `closing existing cursor "%s"` before dropping a duplicate when allowDup is true and dupSilent is false, and PL/pgSQL separately reports ERROR `cursor "%s" already in use` when SPI_cursor_find finds an active named cursor.
-
From 7.4 through 18.6 and 19beta3; the selected portal-manager and PL/pgSQL branches are fixed 18.6 source paths and runtime was not run.
同类错误代码
Class 42 语法错误或访问规则冲突 下的其他成员。
42000syntax_error_or_access_rule_violation42501insufficient_privilege42601syntax_error42602invalid_name42611invalid_column_definition42622name_too_long42701duplicate_column42702ambiguous_column42703undefined_column42704undefined_object42710duplicate_object42712duplicate_alias42723duplicate_function42725ambiguous_function42803grouping_error42804datatype_mismatch42809wrong_object_type42830invalid_foreign_key42846cannot_coerce42883undefined_function428C9generated_always42939reserved_name42P01undefined_table42P02undefined_parameter42P04duplicate_database42P05duplicate_prepared_statement42P06duplicate_schema42P07duplicate_table42P08ambiguous_parameter42P09ambiguous_alias42P10invalid_column_reference42P11invalid_cursor_definition42P12invalid_database_definition42P13invalid_function_definition42P14invalid_prepared_statement_definition42P15invalid_schema_definition42P16invalid_table_definition42P17invalid_object_definition42P18indeterminate_datatype42P19invalid_recursion42P20windowing_error42P21collation_mismatch42P22indeterminate_collation