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

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

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

42883 undefined_function

未定义函数

ERROR 已实测 详解 实测通过

条件名
undefined_function
宏名称
ERRCODE_UNDEFINED_FUNCTION
启用版本
7.4
状态
活跃

版本覆盖

速览

42883undefined_function(未定义函数):按名称和输入类型没有兼容函数。解析器的未定义操作符分支也会使用该条件。本案例在函数不存在时调用模式限定的整数签名。

含义

解析器同时解析名称、模式可见性、输入类型和重载。选定函数组报告 function %s does not exist,提示没有匹配函数;同一 SQLSTATE 的 parse_oper.c 分支会报告 operator does not exist: %s 及对应操作符提示。区分 42725 的候选歧义和 42846 的表达式转换失败。函数要检查 pg_proc/identity arguments,操作符要检查 pg_operator 和两个操作数类型。扩展提供的例程或操作符也可能在当前服务器或版本不可用,因此可用性本身属于诊断范围。

诊断

记录完整名称和签名。函数用 pg_procpg_get_function_identity_arguments 查询,操作符检查 pg_operator 及两个操作数类型。核对 current_schemasearch_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
HINT 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
HINT No operator matches the given name and argument types. You might need to add explicit type casts.
HINT 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 通过;这是有界观察,不能推断所有中间版本或所有源码分支。

来源

证据

断言

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

  • 42883 is the undefined_function condition in Class 42.

    核实方式Read fixed errcodes.txt and locked catalogue metadata.

    不覆盖Identity does not identify every backend call that can reuse this SQLSTATE.

    来源src/backend/utils/errcodes.txt

  • The selected missing_function_resolution follows a resolved PostgreSQL source-call group; other branches can use different dynamic fields.

    核实方式Trace the REL_18_6 and REL_10_23 source-call records at the locked commits.

    不覆盖This is one mechanism boundary, not an exhaustive inventory of the code.

    来源src/backend/parser/parse_func.c · src/backend/parser/parse_func.c

  • Resolve function or operator name, schema visibility, exact argument types, overloads, and extension/server feature availability before changing search_path or casts.

    核实方式Combine the selected source call, registry SQL, and passed structured assertions.

    不覆盖The claim describes the selected path and does not generalize to every branch sharing this SQLSTATE.

    来源src/backend/parser/parse_func.c · src/backend/parser/parse_func.c · src/backend/parser/parse_oper.c · src/backend/parser/parse_oper.c · verify/cases/42883/snippets.json

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

    核实方式Read the complete fixed op_error branch in both locked parse_oper.c snapshots.

    不覆盖The selected runtime exercises the function producer; operator resolution and extension/version availability remain source-only here.

    来源src/backend/parser/parse_oper.c · src/backend/parser/parse_oper.c

  • The selected missing_function_resolution passed on isolated PostgreSQL 18.6 and 10.21 targets.

    核实方式Run the shared SQL registry and inspect SQLSTATE, severity, state, repair, cleanup, and target stop.

    不覆盖Scope is limited to these statements, psycopg, and two versions.

    来源verify/cases/42883/cases.json · verify/cases/42883/snippets.json

  • The locked catalogue records 42883 from the 7.4 presence bound through the listed snapshots; runtime scope is 18.6 and 10.21.

    核实方式Read generated facts, fixed calls, and selected summaries.

    不覆盖Definition presence is not an exact behavioral introduction; two runtime versions do not prove every intermediate behavior.

    来源src/backend/utils/errcodes.txt · raw/calls/REL_18_6.jsonl · raw/calls/REL_10_23.jsonl

运行记录

目标服务器版本结果覆盖案例
latest 18.6 (Homebrew) passed missing_function_resolution
pg10 10.21 (Debian 10.21-1.pgdg90+1) passed missing_function_resolution

同类错误代码

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