百科 / 错误代码 / Class 42 语法错误或访问规则冲突
42P13 invalid_function_definition
无效函数定义
ERROR 源码确认 参考 未实测
- 条件名
invalid_function_definition- 宏名称
ERRCODE_INVALID_FUNCTION_DEFINITION- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
42P13(invalid_function_definition)函数、聚合和触发器声明可能在执行前校验失败。
含义
函数定义校验在声明不兼容时使用此条件。选定的核心路径包括无法确定多态聚合转换类型(DETAIL 由调用方动态生成)、最终语句不是兼容的 SELECT 或 DML RETURNING 而导致返回类型不匹配,以及触发器函数声明参数。
诊断
修改函数前先按消息分类:聚合转换类型推断及其动态 DETAIL、最终语句/RETURNING 结果与声明返回类型不一致,或触发器函数声明参数。把已存签名、返回类型与函数体和触发器约定逐项比较;不返回行的 DML 或 utility 命令与标量强制转换失败属于不同的最终语句路径。
处理
修正消息指出的声明或函数体:为聚合提供可确定的转换类型,让函数最后语句返回声明类型;触发器参数应通过 TG_NARGS/TG_ARGV 读取,不能在声明中列出。检查依赖调用者后再重建或替换。如果 ERROR 发生在显式事务中,执行下一条 DDL 前先 ROLLBACK,或回滚到错误前的保存点。
消息
固定源码中的代表性消息包括:message: cannot determine transition data type; errdetail_internal: %s;message: return type mismatch in function declared to return %s; DETAIL: Function's final statement must be SELECT or INSERT/UPDATE/DELETE/MERGE RETURNING.;message: trigger functions cannot have declared arguments; HINT: The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead.。占位符由实际对象、列或参数填充。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
cannot determine transition data type
%s
%s
来源:src/backend/catalog/pg_aggregate.c(lines 142-145) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
return type mismatch in function declared to return %s
Function's final statement must be SELECT or INSERT/UPDATE/DELETE/MERGE RETURNING.
Function's final statement must be SELECT or INSERT/UPDATE/DELETE/MERGE RETURNING.
来源:src/backend/executor/functions.c(lines 2222-2226) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
trigger functions cannot have declared arguments
The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead.
The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead.
来源:src/pl/plpgsql/src/pl_comp.c(lines 493-496) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
版本
锁定目录显示该条件最早见于 PostgreSQL 7.4;行为说明固定在 PostgreSQL 18.6 源码,目录存在范围不等于每条消息或功能都从该版本开始。
来源
- 上游源码 src/pl/plpgsql/src/pl_comp.c 第 493–496 行
- 上游源码 src/backend/executor/functions.c 第 2222–2226 行
- 上游源码 src/backend/catalog/pg_aggregate.c 第 142–145 行
- 上游源码 src/backend/utils/errcodes.txt 第 394 行
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
42P13 is the invalid_function_definition condition in Class 42.
-
Selected core paths cover a polymorphic aggregate transition type that cannot be determined with a caller-generated internal DETAIL, a function return-type mismatch when the final statement is not a compatible SELECT or DML RETURNING, and trigger functions declaring arguments.
-
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_definition42P14invalid_prepared_statement_definition42P15invalid_schema_definition42P16invalid_table_definition42P17invalid_object_definition42P18indeterminate_datatype42P19invalid_recursion42P20windowing_error42P21collation_mismatch42P22indeterminate_collation