百科 / 错误代码 / Class 42 语法错误或访问规则冲突
42725 ambiguous_function
函数调用歧义
ERROR 已实测 参考 实测通过
- 条件名
ambiguous_function- 宏名称
ERRCODE_AMBIGUOUS_FUNCTION- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
42725 是 ambiguous_function(函数调用歧义):有多个可行候选却无法选出最佳候选。案例定义 uuid/jsonb 重载并传入未知类型字符串。
含义
重载解析考虑字面量类型、cast、模式可见性和签名。unknown 让两个候选都可行,报告 function %s is not unique;它不同于定义冲突 42723 和无候选的 42883。检查可见 pg_proc 与参数类型。
诊断
在 pg_proc 中列出可见候选、identity arguments 和输入类型,并检查字面量推断类型。限定模式只能缩小可见范围,不能在重载之间自动选择。
处理
转换为符合业务含义的类型,或删除非预期重载。这里用 ::uuid 选择 UUID。不要只为消除报错而加 cast,因为它可能改变校验与重载行为。显式事务中的歧义会使事务进入 INERROR,应先回滚或回到合适的 savepoint 再重试;本案例的自动提交会话保持 IDLE。
可复现案例
在一次性实例上执行过的场景。其中 1 个附有可执行 SQL,正文相应小节里给出。
ambiguous_function_call PG 10 / 18 有 SQL
前置条件
- A runner-owned disposable target is provisioned.
触发
Call two uuid/jsonb overloads with an unknown string literal.
断言
- SQLSTATE is 42725 and the diagnostic identifies ambiguous_function(unknown)
- The hint requests explicit type casts and the session remains IDLE
- An explicit uuid cast selects the intended overload
处置
Cast the input to the intended type or remove the overload ambiguity; do not guess from a function name alone.
清理
Drop the runner schema and its overloads.
实测诊断
固定组是 ERROR:function %s is not unique,提示为 Could not choose a best candidate function. You might need to add explicit type casts.
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
function %s is not unique
Could not choose a best candidate function. 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
代表案例
注册表创建两个重载,用未知字符串触发,再显式 UUID cast 并断言返回值。
CREATE FUNCTION syntax_schema.ambiguous_function(uuid) RETURNS text LANGUAGE SQL AS 'SELECT ''uuid''';
CREATE FUNCTION syntax_schema.ambiguous_function(jsonb) RETURNS text LANGUAGE SQL AS 'SELECT ''jsonb''';
SELECT syntax_schema.ambiguous_function('123e4567-e89b-12d3-a456-426614174000');
SELECT syntax_schema.ambiguous_function('123e4567-e89b-12d3-a456-426614174000'::uuid);
选定的 18.6 与 10.21 运行均通过 SQLSTATE、严重级别、状态/恢复、修复、清理和一次性实例停止断言。详见 案例 JSON 与 作者证据;私有清单和注册表哈希也记录在其中。
版本
锁定目录从 7.4 存在边界起包含该条件并列出相关快照。选定自然案例已在 PostgreSQL 18.6 与 10.21 通过;这是有界观察,不能推断所有中间版本或所有源码分支。
来源
- 上游源码 src/backend/parser/parse_func.c 第 499–506 行
- 上游源码 src/backend/parser/parse_func.c 第 570–577 行
- 上游源码 src/backend/utils/errcodes.txt
- 核验材料 verify/cases/42725/cases.json
- 核验材料 verify/cases/42725/snippets.json
- 核验材料 raw/calls/REL_10_23.jsonl
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
42725 is the ambiguous_function condition in Class 42.
-
The selected ambiguous_function_call follows a resolved PostgreSQL source-call group; other branches can use different dynamic fields.
-
The selected ambiguous_function_call passed on isolated PostgreSQL 18.6 and 10.21 targets.
-
The locked catalogue records 42725 from the 7.4 presence bound through the listed snapshots; runtime scope is 18.6 and 10.21.
运行记录
| 目标 | 服务器版本 | 结果 | 覆盖案例 |
|---|---|---|---|
| latest | 18.6 (Homebrew) | passed | ambiguous_function_call |
| pg10 | 10.21 (Debian 10.21-1.pgdg90+1) | passed | ambiguous_function_call |
同类错误代码
Class 42 语法错误或访问规则冲突 下的其他成员。
42000syntax_error_or_access_rule_violation42501insufficient_privilege42601syntax_error42602invalid_name42611invalid_column_definition42622name_too_long42701duplicate_column42702ambiguous_column42703undefined_column42704undefined_object42710duplicate_object42712duplicate_alias42723duplicate_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_definition42P14invalid_prepared_statement_definition42P15invalid_schema_definition42P16invalid_table_definition42P17invalid_object_definition42P18indeterminate_datatype42P19invalid_recursion42P20windowing_error42P21collation_mismatch42P22indeterminate_collation