百科 / 错误代码 / Class 42 语法错误或访问规则冲突
42P06 duplicate_schema
重复模式
ERROR 源码确认 详解 未实测
- 条件名
duplicate_schema- 宏名称
ERRCODE_DUPLICATE_SCHEMA- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
42P06(duplicate_schema)是模式定义冲突。普通 CREATE 报 ERROR;IF NOT EXISTS 可发 NOTICE 并继续,但条件路径只是跳过创建,不会协调已有模式。
含义
NamespaceCreate 发现 pg_namespace 中已有同名行时报告 ERROR schema "%s" already exists。CREATE SCHEMA IF NOT EXISTS 检查同一命名空间后,在创建前报告 NOTICE schema "%s" already exists, skipping。两条报文都指向模式本身,不是其中的关系;固定命令路径先做创建权限检查,NOTICE 不表示已经比较了所有者或定义。
诊断
确认目标数据库和模式,检查 pg_namespace.nspname、所有者/ACL、内容和准确迁移语句。保留严重性:NOTICE 是条件行为并让命令继续,普通 CREATE 的 ERROR 会使显式事务失败。不能从 NOTICE 推出已有模式的所有者、授权、扩展、表或迁移版本符合要求。
处理
仅在所有权、权限和内容符合业务契约时复用。IF NOT EXISTS 不验证也不协调这些属性,需要时应追加明确的所有权、授权和迁移检查。不要删除模式来通过迁移。普通 CREATE 在显式事务中报 ERROR 后,应回滚到合适保存点或回滚事务再继续。
消息变体
选定变体是 schema "%s" already exists(明确 ERROR)和 schema "%s" already exists, skipping(明确 NOTICE)。%s 是动态模式名;两条报文都不保证已有模式的所有者或定义。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
schema "%s" already exists
来源:src/backend/catalog/pg_namespace.c(lines 62-64) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
schema "%s" already exists, skipping
来源:src/backend/commands/schemacmds.c(lines 132-135) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
版本
目录范围从 7.4 到 18.6、19beta3,不是精确的功能引入判断。选定的是 18.6 固定 ERROR 和 NOTICE 源码路径,未运行数据库。
来源
- 上游源码 src/backend/commands/schemacmds.c 第 132–135 行
- 上游源码 src/backend/catalog/pg_namespace.c 第 62–64 行
- 上游源码 src/backend/utils/errcodes.txt 第 382 行
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
42P06 is the duplicate_schema condition in Class 42.
-
NamespaceCreate reports ERROR `schema "%s" already exists` when pg_namespace already contains the name. CREATE SCHEMA IF NOT EXISTS checks the namespace and reports NOTICE `schema "%s" already exists, skipping` before creation; the conditional path does not compare or reconcile owner, ACL, or contents.
-
From 7.4 through 18.6 and 19beta3; this catalogue range is not a precise introduction claim. The selected ERROR and NOTICE branches are fixed 18.6 source paths and runtime was not run.
同类错误代码
Class 42 语法错误或访问规则冲突 下的其他成员。
42000syntax_error_or_access_rule_violation42501insufficient_privilege42601syntax_error42602invalid_name42611invalid_column_definition42622name_too_long42701duplicate_column42702ambiguous_column42703undefined_column42704undefined_object42710duplicate_object42712duplicate_alias42723duplicate_function42725ambiguous_function42803grouping_error42804datatype_mismatch42809wrong_object_type42830invalid_foreign_key42846cannot_coerce42883undefined_function428C9generated_always42939reserved_name42P01undefined_table42P02undefined_parameter42P03duplicate_cursor42P04duplicate_database42P05duplicate_prepared_statement42P07duplicate_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