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

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

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

42602 invalid_name

名称无效

ERROR 已实测 参考 实测通过

条件名
invalid_name
宏名称
ERRCODE_INVALID_NAME
启用版本
7.4
状态
活跃

版本覆盖

速览

SQLSTATE 42602 是 Class 42 中的 invalid_name42602 表示名称无效。选定的 enum 路径拒绝 64 字节标签,主报文为 invalid enum label "%s",并给出长度 DETAIL;随后可以添加短标签。

含义

42602 表示名称无效。在 AddEnumLabel 中,PostgreSQL 会在修改目录前把输入的 enum 标签与 NAMEDATALEN - 1 比较。选定的 64 字节标签因此产生明确的 ERROR,主报文为 invalid enum label "%s",并给出长度 DETAIL;随后可以添加短标签。这是 enum 标签的具体路径,不能据此断言所有无效对象名称都由同一 producer 产生。

诊断

检查对象类型以及 DETAIL 中的准确长度措辞。本批在 18.6 与 10.21 观察 enum 标签路径:18.6 的源码/运行报文是 Labels must be 63 bytes or less.,10.21 是 Labels must be 63 characters or less. 仅凭这两个措辞不能推断长度机制改变;两份固定源码都把标签与 NAMEDATALEN - 1 比较。失败的 DDL 在自动提交中是 ERROR,选定会话仍为 IDLE

处理

使用限制以内的标签,或把较长的用户值存为数据。失败语句返回后再添加合法短标签;选定修复后 enum 中有 okshort。不要静默截断 enum 标签,也不要把该 enum 专用路径推广成所有名称错误。

可复现案例

在一次性实例上执行过的场景。其中 1 个附有可执行 SQL,正文相应小节里给出。

invalid_enum_label PG 10 / 18 有 SQL

前置条件

  • A runner-owned disposable target is provisioned.

触发

Create an enum and add a 64-byte label, exceeding the enum label limit.

断言

  • SQLSTATE is 42602 and the primary identifies an invalid enum label
  • The session remains IDLE
  • Adding a short label succeeds and the enum contains both labels

处置

Use an enum label within the server byte limit or model longer values as data.

清理

Drop the case schema with an owner connection.

报文

选定源码路径以明确的 ERROR 发出主报文 invalid enum label "%s"。DETAIL 在 18.6 为 Labels must be 63 bytes or less.,在 10.21 为 Labels must be 63 characters or less.,标签文本是动态值。只有客户端异常而没有服务器 SQLSTATE、主报文和长度 DETAIL 时,不能据此识别这个选定的 enum 标签子路径;其他固定 producer 可以使用同一 SQLSTATE 和不同诊断。

报文模板

源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。

主消息 invalid enum label "%s"
DETAIL · REL_18_6 Labels must be %d bytes or less.
DETAIL · REL_10_23 Labels must be %d characters or less.

来源:src/backend/catalog/pg_enum.c @ REL_18_6 · src/backend/catalog/pg_enum.c @ REL_10_23

代表案例

本页使用与运行器注册表相同的语句。执行时,syntax_schemasyntax_role 等生成名称会替换为一次性实例中的实际值。

CREATE TYPE syntax_schema.syntax_enum AS ENUM ('ok');
ALTER TYPE syntax_schema.syntax_enum ADD VALUE 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
ALTER TYPE syntax_schema.syntax_enum ADD VALUE 'short';
SELECT enum_range(NULL::syntax_schema.syntax_enum)::text[];

选定的 18.6 运行记录结构化诊断并通过修复断言;10.21 运行通过同一案例的具体检查。可下载的案例和证据投影分别是 42602 案例 JSON作者证据。运行器清单为 verify/cases/42602/cases.json,页面 SQL 会与共享注册表核对。

版本

选定的自然运行范围是 PostgreSQL 18.6 与 10.21,不能据此推断所有中间版本的行为。

来源

证据

断言

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

  • 42602 is the invalid_name condition in Class 42.

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

    不覆盖Directory identity does not identify every backend path.

    来源src/backend/utils/errcodes.txt

  • The fixed source calls for 42602 include the mechanism and message boundary selected for this page.

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

    不覆盖Other calls can use the same SQLSTATE with different context or dynamic fields.

    来源src/backend/catalog/pg_enum.c · src/backend/catalog/pg_enum.c

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

    核实方式Run the shared registry case and inspect structured diagnostics, state/recovery assertions, and cleanup.

    不覆盖This covers the selected case and targets only; it does not generalize to all drivers or intermediate releases.

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

  • The locked catalogue records 42602; runtime scope is limited to the selected targets.

    核实方式Read generated facts and selected summaries.

    不覆盖Definition presence is not an exact behavioral introduction.

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

运行记录

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

同类错误代码

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