百科 / 错误代码 / Class 42 语法错误或访问规则冲突
42622 name_too_long
名称过长
ERROR 源码确认 参考 未实测
- 条件名
name_too_long- 宏名称
ERRCODE_NAME_TOO_LONG- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
SQLSTATE 42622 是 Class 42 中的 name_too_long。42622 表示名称过长。固定源码路径包括超长 SQL 标识符的扫描器 NOTICE 和二进制 name 接收 ERROR;普通文本输入也可能直接截断而不产生这两种诊断。
含义
42622 表示名称过长,并有不止一个 producer。二进制 name 接收函数 namerecv 通过 pq_getmsgtext 读取外部文本,把字节数与 NAMEDATALEN 比较,并在复制值前以 ERROR 发出 identifier too long 和长度 DETAIL。解析器的 truncate_identifier 路径不同:它把超长 SQL 标识符截到多字节边界,然后由扫描器以 warn = true 调用时发出带 SQLSTATE 42622 的 NOTICE,说明标识符将被截断。普通文本输入走独立的 namein,可能静默截断,不会进入 namerecv。
诊断
先区分输入边界和 severity。二进制类型接收失败有 identifier too long 主报文和长度 DETAIL;SQL 标识符可能产生包含原名与截断名的 NOTICE;text cast 到 name 则可能静默截断。二进制输入要记录 format code 和 type OID,扫描器输入则记录准确 SQL 标识符和服务器 NOTICE。本批有意没有选定自然 runtime:选定版本的 text cast 会截断,不能把它当成任一源码分支的证据。固定 guard 不表示每个超长值或标识符都属于同一已观察路径。
处理
在相应输入边界执行长度校验,把较长应用值存为 text 或其他合适类型。如果二进制客户端确实发送了超长 name 值,应在该边界修复编码器或应用 schema;如果问题是扫描器 NOTICE,就缩短或重命名 SQL 标识符并检查目录中的最终名称。不要用 RAISE 伪造此码,不要把静默文本截断当作证据,也不要把一种 severity/path 改报成另一种。
可复现案例
在一次性实例上执行过的场景。
identifier_too_long_boundary PG 10 / 18
前置条件
- The fixed REL_18_6 and REL_10_23 source paths are available.
触发
No ordinary SQL cast is claimed: fixed source shows 42622 in binary name receive, while text casts truncate identifiers before that path.
处置
Use a protocol path that validates the name value before retrying, or keep long user text outside the name type.
清理
No persistent objects; close the runner connection.
报文
固定扫描器分支以明确的 NOTICE 和 SQLSTATE 42622 发出主报文。REL_18_6 的原始主报文模板是 identifier "%s" will be truncated to "%.*s";REL_10_23 是 identifier "%s" will be truncated to "%s"。固定 namerecv 分支以明确的 ERROR 发出主报文 identifier too long 和 DETAIL Identifier must be less than %d characters.;%d 在该源码路径中是 NAMEDATALEN。两者都只在本页确认源码边界,文本输入路径可能静默。只有客户端异常或 NOTICE 而没有服务器 SQLSTATE 及对应扫描器/二进制上下文时,不能识别某个 42622 路径。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
identifier too long
Identifier must be less than %d characters.
来源:src/backend/utils/adt/name.c @ REL_18_6 · src/backend/utils/adt/name.c @ REL_10_23
适用范围:Only the binary name receive path is source-confirmed here.
identifier "%s" will be truncated to "%.*s"
identifier "%s" will be truncated to "%s"
来源:src/backend/parser/scansup.c @ REL_18_6 · src/backend/parser/scansup.c @ REL_10_23
适用范围:Scanner identifier path only; 18.6 and 10.23 use different formatting for the clipped second value.
代表案例
本页没有选定的自然 SQL 运行;这里只记录固定源码边界,不使用伪造触发器。
版本
本页没有选定的自然 SQL 运行;固定的 REL_18_6/REL_10_23 源码边界不能证明所有中间版本的行为。
来源
- 上游源码 src/backend/utils/errcodes.txt
- 上游源码 src/backend/parser/scansup.c 第 187–208 行
- 上游源码 src/backend/parser/scansup.c 第 91–102 行
- 上游源码 src/backend/utils/adt/name.c 第 89–93 行
- 上游源码 src/backend/utils/adt/name.c 第 91–95 行
- 核验材料 verify/cases/42622/cases.json
- 核验材料 raw/calls/REL_10_23.jsonl
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
42622 is the name_too_long condition in Class 42.
-
The fixed source calls for 42622 include the mechanism and message boundary selected for this page.
-
The parser truncates an overlong SQL identifier and can emit a 42622 NOTICE when the scanner requests warning, while binary namerecv emits the separate 42622 ERROR path.
-
The locked catalogue records 42622; runtime scope is limited to the selected targets.
同类错误代码
Class 42 语法错误或访问规则冲突 下的其他成员。
42000syntax_error_or_access_rule_violation42501insufficient_privilege42601syntax_error42602invalid_name42611invalid_column_definition42701duplicate_column42702ambiguous_column42703undefined_column42704undefined_object42710duplicate_object42712duplicate_alias42723duplicate_function42725ambiguous_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