42P06 — 重复模式
要创建的模式名在当前数据库中已存在。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Syntax Error or Access Rule Violation
- condition name
- duplicate_schema
- lang
- en
- sqlstate
- 42P06
版本定义 PG 18
42P06 — 重复模式
速览 {#at-a-glance}
42P06(duplicate_schema)是模式定义冲突。普通 CREATE 报 ERROR;IF NOT EXISTS 可发 NOTICE 并继续,但条件路径只是跳过创建,不会协调已有模式。
含义 {#meaning}
NamespaceCreate 发现 pg_namespace 中已有同名行时报告 ERROR schema "%s" already exists。CREATE SCHEMA IF NOT EXISTS 检查同一命名空间后,在创建前报告 NOTICE schema "%s" already exists, skipping。两条报文都指向模式本身,不是其中的关系;固定命令路径先做创建权限检查,NOTICE 不表示已经比较了所有者或定义。
诊断 {#diagnosis}
确认目标数据库和模式,检查 pg_namespace.nspname、所有者/ACL、内容和准确迁移语句。保留严重性:NOTICE 是条件行为并让命令继续,普通 CREATE 的 ERROR 会使显式事务失败。不能从 NOTICE 推出已有模式的所有者、授权、扩展、表或迁移版本符合要求。
处理 {#response}
仅在所有权、权限和内容符合业务契约时复用。IF NOT EXISTS 不验证也不协调这些属性,需要时应追加明确的所有权、授权和迁移检查。不要删除模式来通过迁移。普通 CREATE 在显式事务中报 ERROR 后,应回滚到合适保存点或回滚事务再继续。
消息变体 {#messages}
选定变体是 schema "%s" already exists(明确 ERROR)和 schema "%s" already exists, skipping(明确 NOTICE)。%s 是动态模式名;两条报文都不保证已有模式的所有者或定义。
版本 {#versions}
目录范围从 7.4 到 18.6、19beta3,不是精确的功能引入判断。选定的是 18.6 固定 ERROR 和 NOTICE 源码路径,未运行数据库。
相关 {#related}
来源 {#sources}
-
src.errcodes.42P06.18.6—src/backend/utils/errcodes.txtline 382,固定于724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-2566e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba(源码)。 -
src.call.42P06.4d5505b63e38ef1b25836623—src/backend/catalog/pg_namespace.clines 62-64,固定于724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-25689675ba1bb9c531ab4f43db8a6f7cac00956561b342e42ea6eaae6b8d0b50d78(源码)。 -
src.call.42P06.373538bec86ad8eedfce8d7a—src/backend/commands/schemacmds.clines 132-135,固定于724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-2565fd5f43dce5f36f06ed390014c06f244564072227d25a22735f594d2170626b1(源码)。 -
src.calls.REL_18_6.42P06— 固定本地核心调用扫描;SHA-2569ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf。 -
作者证据— 记录源码断言、消息角色和运行边界。
比较版本
SQLSTATE 证据与已记录的运行版本
claims · identity.class-and-condition
{
"claim_id": "identity.class-and-condition",
"limits": "Identity does not enumerate all source branches or client failures.",
"method": "Read fixed REL_18_6 errcodes.txt and locked facts.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.42P06.18.6"
],
"statement": "42P06 is the duplicate_schema condition in Class 42."
}claims · mechanism.selected-source-path
{
"claim_id": "mechanism.selected-source-path",
"limits": "Representative confirmed core paths only; not exhaustive historical or extension coverage.",
"method": "Read complete resolved REL_18_6 report groups and message roles.",
"position": 1,
"runtime": [],
"sources": [
"src.call.42P06.4d5505b63e38ef1b25836623",
"src.call.42P06.373538bec86ad8eedfce8d7a"
],
"statement": "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."
}claims · versions.catalogue-boundary
{
"claim_id": "versions.catalogue-boundary",
"limits": "First observed release is a lower bound, not precise behavioral introduction.",
"method": "Read locked catalogue facts and definition snapshots.",
"position": 2,
"runtime": [],
"sources": [
"src.errcodes.42P06.18.6"
],
"statement": "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."
}messages · message.variant-1
{
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"message_id": "message.variant-1",
"path": "",
"position": 0,
"raw": {
"detail_templates": [],
"hint_templates": [],
"id": "message.variant-1",
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"primary_template": "schema \"%s\" already exists",
"roles": [
{
"role": "errmsg",
"template": "schema \"%s\" already exists"
}
],
"severity_source": "explicit ERROR",
"sources": [
"src.call.42P06.4d5505b63e38ef1b25836623"
],
"sqlstate": "42P06"
},
"severity": "explicit ERROR",
"sources": [
"src.call.42P06.4d5505b63e38ef1b25836623"
],
"templates": [
{
"kind": "primary",
"literal": "schema \" \" already exists",
"position": 0,
"role": "",
"template": "schema \"%s\" already exists"
}
]
}messages · message.variant-2
{
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"message_id": "message.variant-2",
"path": "",
"position": 1,
"raw": {
"detail_templates": [],
"hint_templates": [],
"id": "message.variant-2",
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"primary_template": "schema \"%s\" already exists, skipping",
"roles": [
{
"role": "errmsg",
"template": "schema \"%s\" already exists, skipping"
}
],
"severity_source": "explicit NOTICE",
"sources": [
"src.call.42P06.373538bec86ad8eedfce8d7a"
],
"sqlstate": "42P06"
},
"severity": "explicit NOTICE",
"sources": [
"src.call.42P06.373538bec86ad8eedfce8d7a"
],
"templates": [
{
"kind": "primary",
"literal": "schema \" \" already exists, skipping",
"position": 0,
"role": "",
"template": "schema \"%s\" already exists, skipping"
}
]
}sources · src.errcodes.42P06.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "line 382",
"path": "src/backend/utils/errcodes.txt",
"position": 0,
"sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
"source_id": "src.errcodes.42P06.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L382"
}sources · src.call.42P06.4d5505b63e38ef1b25836623
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "lines 62-64",
"path": "src/backend/catalog/pg_namespace.c",
"position": 1,
"sha256": "89675ba1bb9c531ab4f43db8a6f7cac00956561b342e42ea6eaae6b8d0b50d78",
"source_id": "src.call.42P06.4d5505b63e38ef1b25836623",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/pg_namespace.c#L62-L64"
}sources · src.call.42P06.373538bec86ad8eedfce8d7a
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "lines 132-135",
"path": "src/backend/commands/schemacmds.c",
"position": 2,
"sha256": "5fd5f43dce5f36f06ed390014c06f244564072227d25a22735f594d2170626b1",
"source_id": "src.call.42P06.373538bec86ad8eedfce8d7a",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/schemacmds.c#L132-L135"
}sources · src.calls.REL_18_6.42P06
{
"commit": "",
"docs_url": "",
"kind": "local_artifact",
"location": "",
"path": "raw/calls/REL_18_6.jsonl",
"position": 3,
"sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
"source_id": "src.calls.REL_18_6.42P06",
"tag": "",
"url": ""
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:867192f9d416b05d071f1243acf544501328144e33f33798fc55a36bf0af5287
正文语言: zh-Hans · english-manuals:867192f9d416b05d071f1243acf544501328144e33f33798fc55a36bf0af5287