百科 / 错误代码 / Class 42 语法错误或访问规则冲突
42P14 invalid_prepared_statement_definition
无效预备语句定义
ERROR 源码确认 参考 未实测
- 条件名
invalid_prepared_statement_definition- 宏名称
ERRCODE_INVALID_PSTATEMENT_DEFINITION- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
42P14(invalid_prepared_statement_definition)PREPARE 命令可能在定义预备语句时失败。
含义
固定的 18.6 PrepareQuery 路径在注册命名预备语句前,拒绝 SQL PREPARE 的空名称或空指针;这是因为扩展协议有独立的 unnamed 语句槽。因此,协议 Parse 消息中的空名称不自动等于 42P14,空的 SQL 引用标识符也可能先在词法或解析阶段失败。
诊断
准确记录客户端发送的是 SQL PREPARE 还是扩展协议 Parse,并保留语句名。区分 SQL PREPARE 的空名称检查、合法的协议 unnamed 语句、26000(预备语句不存在)以及后续参数/类型错误;空的引用标识符可能在到达此 guard 前就失败。
处理
SQL PREPARE 应使用非空且引用方式一致的语句名。扩展协议若本来要使用 unnamed 语句槽,就保留该协议语义,不要改写成 SQL PREPARE。若名称由框架生成,检查命名层,并确认后续 EXECUTE 与 DEALLOCATE 使用同一会话。显式事务中的 ERROR 之后,下一条命令前仍需 ROLLBACK 或回滚到错误前的保存点。
消息
固定源码中的代表性消息为:invalid statement name: must not be empty(ERROR;没有占位符)。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
invalid statement name: must not be empty
来源:src/backend/commands/prepare.c(lines 73-75) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
版本
锁定目录显示该条件最早见于 PostgreSQL 7.4;行为说明固定在 PostgreSQL 18.6 源码,目录存在范围不等于每条消息或功能都从该版本开始。
来源
- 上游源码 src/backend/commands/prepare.c 第 73–75 行
- 上游源码 src/backend/tcop/postgres.c 第 1433–1459 行
- 上游源码 src/backend/utils/errcodes.txt 第 395 行
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
42P14 is the invalid_prepared_statement_definition condition in Class 42.
-
PrepareQuery rejects a null or empty name for SQL PREPARE before a named statement is registered; its source comment identifies the separate extended-protocol unnamed statement slot. An empty name in a protocol Parse message is therefore not automatically 42P14.
-
Locked catalogue snapshots show this condition by PostgreSQL 7.4; source behavior here is fixed at PostgreSQL 18.6.
同类错误代码
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_parameter42P03duplicate_cursor42P04duplicate_database42P05duplicate_prepared_statement42P06duplicate_schema42P07duplicate_table42P08ambiguous_parameter42P09ambiguous_alias42P10invalid_column_reference42P11invalid_cursor_definition42P12invalid_database_definition42P13invalid_function_definition42P15invalid_schema_definition42P16invalid_table_definition42P17invalid_object_definition42P18indeterminate_datatype42P19invalid_recursion42P20windowing_error42P21collation_mismatch42P22indeterminate_collation