# 42883 — 未定义函数（undefined_function）

> PostgreSQL SQLSTATE 42883（未定义函数，undefined_function）的源码证据、诊断与处理参考。
---

# 42883 — 未定义函数（undefined_function）

## 速览 {#at-a-glance}

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

<!-- BEGIN SQLSTATE FACTS: generated by scripts/generate.py; do not edit -->

| 字段 | 值 |
| --- | --- |
| SQLSTATE | `42883` |
| 条件名 | `undefined_function` |
| 状态 | `有效` |
| 已知存在于 | `7.4` |
| 锁定快照 | `9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3` |
| 宏 | `ERRCODE_UNDEFINED_FUNCTION` |
| 别名 | `—` |

<!-- source facts: data/errcodes/42883.json -->
<!-- END SQLSTATE FACTS -->

## 含义 {#meaning}

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

## 诊断 {#diagnosis}

记录完整名称和签名。函数用 `pg_proc` 与 `pg_get_function_identity_arguments` 查询，操作符检查 `pg_operator` 及两个操作数类型。核对 `current_schema` 与 `search_path`，但不要预设换路径就是正确答案；确认对象是函数、过程、操作符还是扩展提供的特性。若怀疑扩展或版本差异，先检查已安装扩展元数据和 `server_version_num`。

## 处理 {#response}

显式调用预期签名；拥有 API 时在目标模式创建精确函数。若缺失对象由扩展或较新服务器特性提供，只有部署契约要求时才安装或启用该依赖，不要因为查找失败就创建替代品。不要盲目改 `search_path` 或加 cast，它们可能选中另一例程或操作符。案例创建 `missing_function(integer)` 并返回 `42`。显式事务中错误会使事务保持 `INERROR`，应先回滚或回到合适的 savepoint；自动提交错误后为 `IDLE`。

## 实测诊断 {#messages}

选定解析器函数组是 `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 的不同产生路径。

## 代表案例 {#case}

运行器调用缺失模式限定函数，检查展开签名与状态，创建精确整数签名后再次调用。

<!-- BEGIN SQLSTATE SNIPPET: missing_function_resolution -->

```sql
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);
```

<!-- END SQLSTATE SNIPPET -->

选定的 18.6 与 10.21 运行均通过 SQLSTATE、严重级别、状态/恢复、修复、清理和一次性实例停止断言。详见 [`案例 JSON`](../../data/cases/42883.json) 与 [`作者证据`](../../data/evidence/42883.json)；私有清单和注册表哈希也记录在其中。

## 版本 {#versions}

锁定目录从 7.4 存在边界起包含该条件并列出相关快照。选定自然案例已在 PostgreSQL 18.6 与 10.21 通过；这是有界观察，不能推断所有中间版本或所有源码分支。

## 相关 {#related}

- [`42723`](../42723/)
- [`42725`](../42725/)
- [`42846`](../42846/)

## 来源 {#sources}

- `src.errcodes.REL_18_6` — fixed definition at `724edf9bde9d356724ad384a2e196edc3c9f80f7`; SHA-256 `6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L1-L1)).
- `src.undefined-function.18.6` — `src/backend/parser/parse_func.c` lines 629–636 at `724edf9bde9d356724ad384a2e196edc3c9f80f7`; blob SHA-256 `48314eab022297478ac4e49786afaff2621ab7b1d7b50e156668cf477961384f` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_func.c#L629-L636)).
- `src.undefined-function.10.23` — `src/backend/parser/parse_func.c` lines 521–528 at `02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4`; blob SHA-256 `f1b4af88565ca01dbad2b244cd26b42f34764b3f1343b22a9231e271fb0742f2` ([source](https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/backend/parser/parse_func.c#L521-L528)).
- `src.undefined-operator.18.6` — `src/backend/parser/parse_oper.c` lines 619–644 at `724edf9bde9d356724ad384a2e196edc3c9f80f7`; blob SHA-256 `3866ce3302c2a4bd22d0f1d113a4bbc627278a618d5e7b83660e36240cbdd0a8` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_oper.c#L619-L644)).
- `src.undefined-operator.10.23` — `src/backend/parser/parse_oper.c` lines 706–728 at `02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4`; blob SHA-256 `5802db6d55bdb41f9cad4957384fa2c2ddbb4dc902c33f5f57e8a07760761d10` ([source](https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/backend/parser/parse_oper.c#L706-L728)).
- `src.calls.REL_18_6` / `src.calls.REL_10_23` — fixed call scans, SHA-256 `9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf` / `00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c`.
- `manifest.42883` / `snippet-registry.42883` — hashes are recorded in `evidence/42883.json` and each runtime record.
