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

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

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

42710 duplicate_object

重复对象

ERROR 已实测 详解 实测通过

条件名
duplicate_object
宏名称
ERRCODE_DUPLICATE_OBJECT
启用版本
7.4
状态
活跃

版本覆盖

速览

42710 is duplicate_object(重复对象):定义与已占用的对象名冲突。本页选择第二次 CREATE TYPE ... AS ENUM;同一 SQLSTATE 也会用于其他对象定义,因此必须先确认对象种类和模式。

含义

DefineEnum 路径报告 type "%s" already exists,这是目录定义冲突,不是行级唯一性错误。CREATE OR REPLACE 不是通用修复。检查 pg_typepg_namespace、owner 和迁移顺序。选定自动提交错误后为 IDLE;显式事务必须先回滚。

诊断

先确认对象种类和模式。类型查询 pg_type 与 pg_namespace,关系使用 to_regclass,例程检查 pg_proc 和 pg_get_function_identity_arguments;同时核对 owner 与迁移顺序。

处理

使用确认空闲的名称,或仅在已有对象属于自己且该对象支持时执行特定 ALTER/REPLACE。案例以新 ENUM 名称修复。预检查不能消除并发创建竞争,删除未知对象不安全。显式事务中的定义失败会进入 INERROR,应先回滚或回到合适的 savepoint 再重试;本案例的自动提交路径保持 IDLE

可复现案例

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

duplicate_object_type PG 10 / 18 有 SQL

前置条件

  • A runner-owned disposable target is provisioned.

触发

Create the same ENUM type name twice in the runner schema.

断言

  • SQLSTATE is 42710 with the duplicate type message and its naming hint
  • The failed autocommit session remains IDLE
  • Creating a nonconflicting type and inspecting pg_type succeeds

处置

Use a distinct type name after confirming the existing type; do not drop an unknown owner's object.

清理

Drop the runner schema and all types it owns.

实测诊断

该 ENUM 分支的固定 ERROR 主报文没有提示;其他 42710 分支可能有不同模板,heap.c 的关系/类型提示不适用于本分支。

报文模板

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

代表案例

一次性案例创建 ENUM、重复定义并检查代码与状态,再创建不同名类型并核对两个目录项。

CREATE TYPE syntax_schema.duplicate_object_type AS ENUM ('first');
CREATE TYPE syntax_schema.duplicate_object_type AS ENUM ('first');
CREATE TYPE syntax_schema.duplicate_object_type_repaired AS ENUM ('first');
SELECT count(*) FROM pg_type t JOIN pg_namespace n ON n.oid = t.typnamespace WHERE n.nspname = 'syntax_schema_name' AND t.typname IN ('duplicate_object_type', 'duplicate_object_type_repaired');

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

版本

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

来源

证据

断言

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

  • 42710 is the duplicate_object condition in Class 42.

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

    不覆盖Identity does not identify every backend call that can reuse this SQLSTATE.

    来源src/backend/utils/errcodes.txt

  • The selected duplicate_object_type follows a resolved PostgreSQL source-call group; other branches can use different dynamic fields.

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

    不覆盖This is one mechanism boundary, not an exhaustive inventory of the code.

    来源src/backend/commands/typecmds.c · src/backend/commands/typecmds.c

  • ENUM type definitions collide by name; inspect pg_type/pg_namespace and use a deliberate distinct name.

    核实方式Combine the selected source call, registry SQL, and passed structured assertions.

    不覆盖The claim describes the selected path and does not generalize to every branch sharing this SQLSTATE.

    来源src/backend/commands/typecmds.c · src/backend/commands/typecmds.c · verify/cases/42710/snippets.json

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

    核实方式Run the shared SQL registry and inspect SQLSTATE, severity, state, repair, cleanup, and target stop.

    不覆盖Scope is limited to these statements, psycopg, and two versions.

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

  • The locked catalogue records 42710 from the 7.4 presence bound through the listed snapshots; runtime scope is 18.6 and 10.21.

    核实方式Read generated facts, fixed calls, and selected summaries.

    不覆盖Definition presence is not an exact behavioral introduction; two runtime versions do not prove every intermediate behavior.

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

运行记录

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

同类错误代码

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