文档 / SQL 状态码 / Class 42 语法错误或访问规则冲突
42883 undefined_function
未定义函数
ERROR 已实测 详解 实测通过
- 条件名
undefined_function- 宏名称
ERRCODE_UNDEFINED_FUNCTION- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
42883 是 undefined_function(未定义函数):按名称和输入类型没有兼容函数。解析器的未定义操作符分支也会使用该条件。本案例在函数不存在时调用模式限定的整数签名。
含义
解析器同时解析名称、模式可见性、输入类型和重载。选定函数组报告 function %s does not exist,提示没有匹配函数;同一 SQLSTATE 的 parse_oper.c 分支会报告 operator does not exist: %s 及对应操作符提示。区分 42725 的候选歧义和 42846 的表达式转换失败。函数要检查 pg_proc/identity arguments,操作符要检查 pg_operator 和两个操作数类型。扩展提供的例程或操作符也可能在当前服务器或版本不可用,因此可用性本身属于诊断范围。
诊断
记录完整名称和签名。函数用 pg_proc 与 pg_get_function_identity_arguments 查询,操作符检查 pg_operator 及两个操作数类型。核对 current_schema 与 search_path,但不要预设换路径就是正确答案;确认对象是函数、过程、操作符还是扩展提供的特性。若怀疑扩展或版本差异,先检查已安装扩展元数据和 server_version_num。
处理
显式调用预期签名;拥有 API 时在目标模式创建精确函数。若缺失对象由扩展或较新服务器特性提供,只有部署契约要求时才安装或启用该依赖,不要因为查找失败就创建替代品。不要盲目改 search_path 或加 cast,它们可能选中另一例程或操作符。案例创建 missing_function(integer) 并返回 42。显式事务中错误会使事务保持 INERROR,应先回滚或回到合适的 savepoint;自动提交错误后为 IDLE。
可复现案例
在一次性实例上执行过的场景。其中 1 个附有可执行 SQL,正文相应小节里给出。
missing_function_resolution PG 10 / 18 有 SQL
前置条件
- A runner-owned disposable target is provisioned.
触发
Call a schema-qualified function with an integer argument before that signature exists.
断言
- SQLSTATE is 42883 and the diagnostic names the missing function signature
- The failed autocommit session remains IDLE
- Creating the exact integer signature then returns 42
处置
Check schema visibility, function/operator name, argument types, and overload resolution; create or call the intended signature rather than blindly changing search_path.
清理
Drop the runner schema and its function.
实测诊断
选定解析器函数组是 ERROR:主报文 function %s does not exist,提示为 No function matches the given name and argument types. You might need to add explicit type casts. 仅源码确认的操作符组同样是 ERROR:主报文 operator does not exist: %s;两个操作数类型已知时提示为 No operator matches the given name and argument types. You might need to add explicit type casts.,缺少一个操作数类型时使用单数 type 版本。这些是共享 42883 的不同产生路径。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
function %s does not exist
No function matches the given name and argument types. You might need to add explicit type casts.
来源:src/backend/parser/parse_func.c @ REL_18_6 · src/backend/parser/parse_func.c @ REL_10_23
operator does not exist: %s
No operator matches the given name and argument types. You might need to add explicit type casts.
No operator matches the given name and argument type. You might need to add an explicit type cast.
来源:src/backend/parser/parse_oper.c @ REL_18_6 · src/backend/parser/parse_oper.c @ REL_10_23
代表案例
运行器调用缺失模式限定函数,检查展开签名与状态,创建精确整数签名后再次调用。
SELECT syntax_schema.missing_function(41);
CREATE FUNCTION syntax_schema.missing_function(integer) RETURNS integer LANGUAGE SQL AS 'SELECT $1 + 1';
SELECT syntax_schema.missing_function(41);
选定的 18.6 与 10.21 运行均通过 SQLSTATE、严重级别、状态/恢复、修复、清理和一次性实例停止断言。详见 案例 JSON 与 作者证据;私有清单和注册表哈希也记录在其中。
版本
锁定目录从 7.4 存在边界起包含该条件并列出相关快照。选定自然案例已在 PostgreSQL 18.6 与 10.21 通过;这是有界观察,不能推断所有中间版本或所有源码分支。
来源
- 上游源码 src/backend/utils/errcodes.txt
- 上游源码 src/backend/parser/parse_func.c 第 521–528 行
- 上游源码 src/backend/parser/parse_func.c 第 629–636 行
- 上游源码 src/backend/parser/parse_oper.c 第 706–728 行
- 上游源码 src/backend/parser/parse_oper.c 第 619–644 行
- 核验材料 verify/cases/42883/cases.json
- 核验材料 verify/cases/42883/snippets.json
- 核验材料 raw/calls/REL_10_23.jsonl
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
42883 is the undefined_function condition in Class 42.
-
The selected missing_function_resolution follows a resolved PostgreSQL source-call group; other branches can use different dynamic fields.
-
Resolve function or operator name, schema visibility, exact argument types, overloads, and extension/server feature availability before changing search_path or casts.
-
parse_oper.c reuses 42883 for an unresolved operator and formats the operator signature with a plural or singular operand-type hint depending on which argument types are known.
-
The selected missing_function_resolution passed on isolated PostgreSQL 18.6 and 10.21 targets.
-
The locked catalogue records 42883 from the 7.4 presence bound through the listed snapshots; runtime scope is 18.6 and 10.21.
运行记录
| 目标 | 服务器版本 | 结果 | 覆盖案例 |
|---|---|---|---|
| latest | 18.6 (Homebrew) | passed | missing_function_resolution |
| pg10 | 10.21 (Debian 10.21-1.pgdg90+1) | passed | missing_function_resolution |
同类 SQL 状态码
| 状态码 | 条件名 | 宏名称 | 严重等级 | 版本 |
|---|---|---|---|---|
| 42000 | syntax_error_or_access_rule_violation | ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION |
ERROR | 7.4 |
| 语法错误或访问规则违反的总类,见具体子码。 | 活跃 | |||
| 42501 | insufficient_privilege | ERRCODE_INSUFFICIENT_PRIVILEGE |
ERROR | 7.4 |
| 当前角色对目标对象的权限不足。 | 活跃 | |||
| 42601 | syntax_error | ERRCODE_SYNTAX_ERROR |
ERROR | 7.4 |
| SQL 语句存在语法错误,解析器拒绝执行。 | 活跃 | |||
| 42602 | invalid_name | ERRCODE_INVALID_NAME |
ERROR | 7.4 |
| 名称不合法,如 enum 标签超出长度限制。 | 活跃 | |||
| 42611 | invalid_column_definition | ERRCODE_INVALID_COLUMN_DEFINITION |
ERROR | 7.4 |
| 列定义无效,如继承的父表默认值冲突。 | 活跃 | |||
| 42622 | name_too_long | ERRCODE_NAME_TOO_LONG |
ERROR | 7.4 |
| 标识符或 name 值超出长度上限。 | 活跃 | |||
| 42701 | duplicate_column | ERRCODE_DUPLICATE_COLUMN |
ERROR | 7.4 |
| 同一定义中重复指定了同名列。 | 活跃 | |||
| 42702 | ambiguous_column | ERRCODE_AMBIGUOUS_COLUMN |
ERROR | 7.4 |
| 列引用有歧义,多个表都有该列名。 | 活跃 | |||
| 42703 | undefined_column | ERRCODE_UNDEFINED_COLUMN |
ERROR | 7.4 |
| 引用的列在目标关系中不存在。 | 活跃 | |||
| 42704 | undefined_object | ERRCODE_UNDEFINED_OBJECT |
ERROR | 7.4 |
| 引用的数据库对象不存在,如触发器或类型。 | 活跃 | |||
| 42710 | duplicate_object | ERRCODE_DUPLICATE_OBJECT |
ERROR | 7.4 |
| 要定义的对象名已被占用,如重复 CREATE TYPE。 | 活跃 | |||
| 42712 | duplicate_alias | ERRCODE_DUPLICATE_ALIAS |
ERROR | 7.4 |
| 同一查询命名空间中重复使用了表别名。 | 活跃 | |||
| 42723 | duplicate_function | ERRCODE_DUPLICATE_FUNCTION |
ERROR | 7.4 |
| 同一模式下已存在同名同参数类型的函数。 | 活跃 | |||
| 42725 | ambiguous_function | ERRCODE_AMBIGUOUS_FUNCTION |
ERROR | 7.4 |
| 函数调用有多个候选,无法选出最佳匹配。 | 活跃 | |||
| 42803 | grouping_error | ERRCODE_GROUPING_ERROR |
ERROR | 7.4 |
| 分组查询输出了既未分组也未聚合的列。 | 活跃 | |||
| 42804 | datatype_mismatch | ERRCODE_DATATYPE_MISMATCH |
ERROR | 7.4 |
| 表达式类型与目标上下文要求的类型不符。 | 活跃 | |||
| 42809 | wrong_object_type | ERRCODE_WRONG_OBJECT_TYPE |
ERROR | 7.4 |
| 命令本身有效,但不能作用于该类对象。 | 活跃 | |||
| 42830 | invalid_foreign_key | ERRCODE_INVALID_FOREIGN_KEY |
ERROR | 7.4 |
| 外键在被引用列上找不到合格的唯一键。 | 活跃 | |||
| 42846 | cannot_coerce | ERRCODE_CANNOT_COERCE |
ERROR | 7.4 |
| 源类型到目标类型之间没有可用的 cast。 | 活跃 | |||
| 42883 | undefined_function | ERRCODE_UNDEFINED_FUNCTION |
ERROR | 7.4 |
| 按名称和参数类型找不到匹配的函数或操作符。 | 活跃 | |||
| 428C9 | generated_always | ERRCODE_GENERATED_ALWAYS |
ERROR | 10 |
| 向身份列或生成列赋值,这类列只接受 DEFAULT。 | 活跃 | |||
| 42939 | reserved_name | ERRCODE_RESERVED_NAME |
ERROR | 7.4 |
| 对象名使用了保留名称,如模式或表空间。 | 活跃 | |||
| 42P01 | undefined_table | ERRCODE_UNDEFINED_TABLE |
ERROR | 7.4 |
| 引用的表、视图或其他关系不存在。 | 活跃 | |||
| 42P02 | undefined_parameter | ERRCODE_UNDEFINED_PARAMETER |
ERROR | 7.4 |
| 查询引用了解析器未知的位置参数,如 $1。 | 活跃 | |||
| 42P03 | duplicate_cursor | ERRCODE_DUPLICATE_CURSOR |
ERROR | 7.4 |
| 游标或 portal 名称与已有的冲突。 | 活跃 | |||
| 42P04 | duplicate_database | ERRCODE_DUPLICATE_DATABASE |
ERROR | 7.4 |
| 集群中已存在同名数据库。 | 活跃 | |||
| 42P05 | duplicate_prepared_statement | ERRCODE_DUPLICATE_PSTATEMENT |
ERROR | 7.4 |
| 当前会话已有同名的服务端预备语句。 | 活跃 | |||
| 42P06 | duplicate_schema | ERRCODE_DUPLICATE_SCHEMA |
ERROR | 7.4 |
| 要创建的模式名在当前数据库中已存在。 | 活跃 | |||
| 42P07 | duplicate_table | ERRCODE_DUPLICATE_TABLE |
ERROR | 7.4 |
| 关系名已存在,或继承父项重复。 | 活跃 | |||
| 42P08 | ambiguous_parameter | ERRCODE_AMBIGUOUS_PARAMETER |
ERROR | 7.4 |
| 参数存在但无法推导出一致而具体的类型。 | 活跃 | |||
| 42P09 | ambiguous_alias | ERRCODE_AMBIGUOUS_ALIAS |
ERROR | 7.4 |
| 一个表引用对应多个关系命名空间项。 | 活跃 | |||
| 42P10 | invalid_column_reference | ERRCODE_INVALID_COLUMN_REFERENCE |
ERROR | 7.4 |
| 列引用不符合该操作的契约,如 COPY 生成列。 | 活跃 | |||
| 42P11 | invalid_cursor_definition | ERRCODE_INVALID_CURSOR_DEFINITION |
ERROR | 7.4 |
| 游标声明违反定义阶段规则,如 SCROLL 选项冲突。 | 活跃 | |||
| 42P12 | invalid_database_definition | ERRCODE_INVALID_DATABASE_DEFINITION |
ERROR | 7.4 |
| 数据库定义无效,核心源码中未见触发路径。 | 活跃 | |||
| 42P13 | invalid_function_definition | ERRCODE_INVALID_FUNCTION_DEFINITION |
ERROR | 7.4 |
| 函数、聚合或触发器声明在校验阶段失败。 | 活跃 | |||
| 42P14 | invalid_prepared_statement_definition | ERRCODE_INVALID_PSTATEMENT_DEFINITION |
ERROR | 7.4 |
| PREPARE 定义预备语句时失败。 | 活跃 | |||
| 42P15 | invalid_schema_definition | ERRCODE_INVALID_SCHEMA_DEFINITION |
ERROR | 7.4 |
| CREATE SCHEMA 的模式声明不一致被拒绝。 | 活跃 | |||
| 42P16 | invalid_table_definition | ERRCODE_INVALID_TABLE_DEFINITION |
ERROR | 7.4 |
| 表定义无效,如分区键或主键规则冲突。 | 活跃 | |||
| 42P17 | invalid_object_definition | ERRCODE_INVALID_OBJECT_DEFINITION |
ERROR | 7.4 |
| 对象定义无效,如继承、生成列或规则冲突。 | 活跃 | |||
| 42P18 | indeterminate_datatype | ERRCODE_INDETERMINATE_DATATYPE |
ERROR | 7.4 |
| 无法推断表达式或参数的数据类型。 | 活跃 | |||
| 42P19 | invalid_recursion | ERRCODE_INVALID_RECURSION |
ERROR | 8.4 |
| 递归查询结构不合法,执行前被检查拒绝。 | 活跃 | |||
| 42P20 | windowing_error | ERRCODE_WINDOWING_ERROR |
ERROR | 8.4 |
| 窗口函数调用或框架边界定义不合法。 | 活跃 | |||
| 42P21 | collation_mismatch | ERRCODE_COLLATION_MISMATCH |
ERROR | 9.1 |
| 参与运算的排序规则不兼容,产生冲突。 | 活跃 | |||
| 42P22 | indeterminate_collation | ERRCODE_INDETERMINATE_COLLATION |
ERROR | 9.1 |
| 操作需要唯一排序规则,但无法确定。 | 活跃 | |||