# 54023 — too_many_arguments

> PostgreSQL SQLSTATE 54023 的来源与诊断参考。
---

# 54023

## 速览 {#at-a-glance}
`54023` 是函数、过程、聚合和返回集合调用的参数数量上限。固定路径保护 catalog 数组、parser 节点和 executor `FunctionCallInfo` 存储，并按单复数报告编译时实际限制。

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

| 字段 | 值 |
| --- | --- |
| SQLSTATE | `54023` |
| 条件名 | `too_many_arguments` |
| 状态 | `有效` |
| 已知存在于 | `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_TOO_MANY_ARGUMENTS` |
| 别名 | `—` |

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

## 含义 {#meaning}
固定构建在 `pg_config_manual.h` 中把 `FUNC_MAX_ARGS` 定义为 100；源码说明实际可行上限约为 600，修改它需要完整重编 backend（包括 C 函数）。函数定义统计输入参数，明确不统计 output 参数。聚合定义和聚合调用使用 `FUNC_MAX_ARGS - 1`，为 transition/final function 保留可表示空间。函数/过程 parser 与 executor guard 还覆盖显式参数、默认参数、SRF 和保存的 window expression。调用者和对象类型决定修复。

## 报文 {#messages}

| 源码路径 | 精确 primary 模板（单数 / 复数） | `%d` 的计数上限 |
| --- | --- | --- |
| `pg_proc.c` 函数定义 | `functions cannot have more than %d argument` / `functions cannot have more than %d arguments` | 将 `parameterCount`（input 参数数组长度，不含 output 参数）与 `FUNC_MAX_ARGS` 比较；`%d` 传入 `FUNC_MAX_ARGS`（100） |
| `functioncmds.c` 过程调用 | `cannot pass more than %d argument to a procedure` / `cannot pass more than %d arguments to a procedure` | 将 `nargs = list_length(fexpr->args)` 与 `FUNC_MAX_ARGS` 比较；`%d` 传入 `FUNC_MAX_ARGS` |
| `parse_func.c`、`execExpr.c`、`execSRF.c`、`nodeWindowAgg.c` 函数/SRF/window 调用 | `cannot pass more than %d argument to a function` / `cannot pass more than %d arguments to a function` | 将 `list_length(fargs)`、`nargs`、`list_length(sexpr->args)` 或 `perfuncstate->numArguments` 与 `FUNC_MAX_ARGS` 比较；`%d` 传入 `FUNC_MAX_ARGS` |
| `pg_aggregate.c` 聚合定义/调用 | `aggregates cannot have more than %d argument` / `aggregates cannot have more than %d arguments` | 将 `numArgs` 与 `FUNC_MAX_ARGS - 1` 比较；`%d` 传入 99，为 transition/final function 预留槽位 |

这些是 `errmsg_plural` 分组，客户端应保留服务器的单复数渲染和实际上限，不要只搜索一条手写字符串。

## 诊断 {#diagnosis}
先确认是在 CREATE/定义阶段还是调用阶段，以及对象是函数、过程、聚合、SRF 还是 window aggregate。统计显式参数和 parser 展开的默认参数；聚合使用更严格的 `FUNC_MAX_ARGS - 1` 边界。保留消息的单复数 primary 与上限，并检查 stored view/plan 是否由不同 `FUNC_MAX_ARGS` 的二进制建立。

## 处理 {#response}
减少参数，把相关值组合为复合/record 类型，或重设计函数边界。修改过程或聚合签名时同步依赖调用者；不要静默丢弃参数、把 output 参数当 input 计数，也不要假设聚合和普通函数共用同一上限。修改 `FUNC_MAX_ARGS` 是构建级兼容决策，不是会话参数。显式事务中若发生 `ERROR`，重试前执行 `ROLLBACK` 或 `ROLLBACK TO SAVEPOINT`；自动提交只有在定义或调用已改到固定计数以内后才能重试。

## 版本 {#versions}
锁定目录从 7.4 记录；引用 macro、catalog、parser、executor、aggregate 和 SRF 路径来自 PostgreSQL 18.6，未创建超大签名或调用。

## 相关 {#related}
[`54011`](../54011/)、[`54000`](../54000/)、[`42883`](../42883/)

## 来源 {#sources}
[`src/backend/catalog/pg_proc.c#L156-L161`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/pg_proc.c#L156)

[`src/backend/commands/functioncmds.c#L2261-L2266`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/functioncmds.c#L2261)

[`src/backend/executor/execExpr.c#L2727-L2732`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/execExpr.c#L2727)

[`src/backend/executor/execSRF.c#L716-L721`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/execSRF.c#L716)

[`src/include/pg_config_manual.h#L31-L43`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/include/pg_config_manual.h#L31)

[`src/backend/catalog/pg_aggregate.c#L121-L132`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/pg_aggregate.c#L121)

[`src/backend/parser/parse_func.c#L129-L142`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_func.c#L129)

[`src/backend/executor/nodeWindowAgg.c#L1042-L1054`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeWindowAgg.c#L1042)

结构化[证据记录](../../data/evidence/54023.json)保存固定消息以及源码/运行边界。
