↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

42P07 — 重复表或关系定义

关系名已存在,或继承父项重复。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

aliases
未知
class name
Syntax Error or Access Rule Violation
condition name
duplicate_table
lang
en
sqlstate
42P07

版本定义 PG 18

42P07 — 重复表或关系定义

速览 {#at-a-glance}

42P07(duplicate_table)覆盖关系名称冲突、条件 DDL 的 NOTICE,以及继承父项重复或继承环,应先识别操作。

含义 {#meaning}

18.6 核心路径中,表、序列、索引和 CREATE TABLE AS 冲突均报告 relation "%s" already exists。这些对象共享 pg_class 关系命名空间,因此另一种关系类型的同名对象也会造成冲突。索引的 IF NOT EXISTS 路径报告 NOTICE relation "%s" already exists, skipping 并直接返回,不检查已有索引定义是否符合请求。继承路径还对重复父项和 circular inheritance not allowed 使用此 SQLSTATE,后者 DETAIL 为 "%s" is already a child of "%s".。

诊断 {#diagnosis}

名称冲突查 pg_class/pg_namespace,并把序列、索引、表、视图和物化视图纳入检查。IF NOT EXISTS 的 NOTICE 还要核对已有对象的所有者、持久性、列、索引和选项,不能把源码中的名称检查当成定义比较。继承报文查 pg_inherits 和完整父列表,区分父项重复与继承环。

处理 {#response}

只有确认已有定义可接受时才使用幂等 DDL;关系名称冲突可选择采用已有对象或制定对象级迁移。重复父项应从父列表移除重复项,继承环则要打破父图并复核 pg_inherits;单纯改名不能修复父图。显式事务中的 ERROR 应先回滚保存点或回滚事务再查目录;NOTICE 路径无需该恢复。

消息变体 {#messages}

代表变体如下:

| 路径 | 严重性 | 主消息 | DETAIL | | --- | --- | --- | --- | | 关系名称冲突 | ERROR | relation "%s" already exists | 无 | | 索引 IF NOT EXISTS 冲突 | NOTICE | relation "%s" already exists, skipping | 无 | | 继承父项重复 | ERROR | relation "%s" would be inherited from more than once | 无 | | 继承成环 | ERROR | circular inheritance not allowed | "%s" is already a child of "%s". |

版本 {#versions}

目录范围从 7.4 到 18.6、19beta3,不是精确的功能引入判断。选定的 18.6 路径覆盖关系名称查找、索引 IF NOT EXISTS、继承父项重复和继承环;未运行数据库。

相关 {#related}

来源 {#sources}

  • src.errcodes.42P07.18.6 — src/backend/utils/errcodes.txt line 383,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba(源码)。

  • src.call.42P07.694fcfd426e95ce13263fb9a — src/backend/catalog/heap.c lines 1194-1196,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 e720ee58279590793edd0985b3c910970ef56e7361b8ef92e245370587e02a0e(源码)。

  • src.call.42P07.38d8697cf62c00c05657a6d4 — src/backend/catalog/index.c lines 898-901,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 98a4156a5c21ae856a3b583b633cdeb578a5b69910386c9f166d69fcb04ba2d0(源码)。

  • src.call.42P07.30cb2a5359e1ec4bea60a466 — src/backend/commands/tablecmds.c lines 875-878,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 422dc8e833df4940755973c757e338295822ba3e4c7266c40669f49f96eb15a9(源码)。

  • src.call.42P07.19ee2522385544dc7ceb62bb — src/backend/commands/tablecmds.c lines 17376-17381,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 422dc8e833df4940755973c757e338295822ba3e4c7266c40669f49f96eb15a9(源码)。

  • src.calls.REL_18_6.42P07 — 固定本地核心调用扫描;SHA-256 9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf。

  • 作者证据 — 记录源码断言、消息角色和运行边界。

比较版本

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.42P07.18.6"
  ],
  "statement": "42P07 is the duplicate_table 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.42P07.694fcfd426e95ce13263fb9a",
    "src.call.42P07.38d8697cf62c00c05657a6d4",
    "src.call.42P07.index-if-not-exists-guard",
    "src.call.42P07.30cb2a5359e1ec4bea60a466",
    "src.call.42P07.19ee2522385544dc7ceb62bb"
  ],
  "statement": "Core 18.6 paths use the shared pg_class relation namespace for table, sequence, index, and CREATE TABLE AS name collisions. The index IF NOT EXISTS guard reports NOTICE `relation \"%s\" already exists, skipping` and returns on a name hit without definition comparison. Inheritance uses the code for repeated parents and for `circular inheritance not allowed` with DETAIL `\"%s\" is already a child of \"%s\".`"
}
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.42P07.18.6"
  ],
  "statement": "From 7.4 through 18.6 and 19beta3; this catalogue range is not a precise introduction claim. The selected source covers relation lookup, index IF NOT EXISTS, repeated inheritance parents, and circularity; 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": "relation \"%s\" already exists",
    "roles": [
      {
        "role": "errmsg",
        "template": "relation \"%s\" already exists"
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P07.694fcfd426e95ce13263fb9a"
    ],
    "sqlstate": "42P07"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P07.694fcfd426e95ce13263fb9a"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "relation \" \" already exists",
      "position": 0,
      "role": "",
      "template": "relation \"%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": "relation \"%s\" already exists, skipping",
    "roles": [
      {
        "role": "errmsg",
        "template": "relation \"%s\" already exists, skipping"
      }
    ],
    "severity_source": "explicit NOTICE",
    "sources": [
      "src.call.42P07.38d8697cf62c00c05657a6d4"
    ],
    "sqlstate": "42P07"
  },
  "severity": "explicit NOTICE",
  "sources": [
    "src.call.42P07.38d8697cf62c00c05657a6d4"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "relation \" \" already exists, skipping",
      "position": 0,
      "role": "",
      "template": "relation \"%s\" already exists, skipping"
    }
  ]
}
messages · message.variant-3
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-3",
  "path": "",
  "position": 2,
  "raw": {
    "detail_templates": [],
    "hint_templates": [],
    "id": "message.variant-3",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "relation \"%s\" would be inherited from more than once",
    "roles": [
      {
        "role": "errmsg",
        "template": "relation \"%s\" would be inherited from more than once"
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P07.30cb2a5359e1ec4bea60a466"
    ],
    "sqlstate": "42P07"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P07.30cb2a5359e1ec4bea60a466"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "relation \" \" would be inherited from more than once",
      "position": 0,
      "role": "",
      "template": "relation \"%s\" would be inherited from more than once"
    }
  ]
}
messages · message.variant-4
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-4",
  "path": "",
  "position": 3,
  "raw": {
    "detail_templates": [
      "\"%s\" is already a child of \"%s\"."
    ],
    "hint_templates": [],
    "id": "message.variant-4",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "circular inheritance not allowed",
    "roles": [
      {
        "role": "errmsg",
        "template": "circular inheritance not allowed"
      },
      {
        "role": "errdetail",
        "template": "\"%s\" is already a child of \"%s\"."
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P07.19ee2522385544dc7ceb62bb"
    ],
    "sqlstate": "42P07"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P07.19ee2522385544dc7ceb62bb"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "circular inheritance not allowed",
      "position": 0,
      "role": "",
      "template": "circular inheritance not allowed"
    },
    {
      "kind": "detail",
      "literal": "\" \" is already a child of \" \".",
      "position": 1,
      "role": "",
      "template": "\"%s\" is already a child of \"%s\"."
    },
    {
      "kind": "primary",
      "literal": "\" \" is already a child of \" \".",
      "position": 2,
      "role": "errdetail",
      "template": "\"%s\" is already a child of \"%s\"."
    }
  ]
}
sources · src.errcodes.42P07.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "line 383",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.42P07.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L383"
}
sources · src.call.42P07.694fcfd426e95ce13263fb9a
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 1194-1196",
  "path": "src/backend/catalog/heap.c",
  "position": 1,
  "sha256": "e720ee58279590793edd0985b3c910970ef56e7361b8ef92e245370587e02a0e",
  "source_id": "src.call.42P07.694fcfd426e95ce13263fb9a",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/heap.c#L1194-L1196"
}
sources · src.call.42P07.38d8697cf62c00c05657a6d4
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 898-901",
  "path": "src/backend/catalog/index.c",
  "position": 2,
  "sha256": "98a4156a5c21ae856a3b583b633cdeb578a5b69910386c9f166d69fcb04ba2d0",
  "source_id": "src.call.42P07.38d8697cf62c00c05657a6d4",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/index.c#L898-L901"
}
sources · src.call.42P07.index-if-not-exists-guard
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 894-903",
  "path": "src/backend/catalog/index.c",
  "position": 3,
  "sha256": "98a4156a5c21ae856a3b583b633cdeb578a5b69910386c9f166d69fcb04ba2d0",
  "source_id": "src.call.42P07.index-if-not-exists-guard",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/index.c#L894-L903"
}
sources · src.call.42P07.30cb2a5359e1ec4bea60a466
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 875-878",
  "path": "src/backend/commands/tablecmds.c",
  "position": 4,
  "sha256": "422dc8e833df4940755973c757e338295822ba3e4c7266c40669f49f96eb15a9",
  "source_id": "src.call.42P07.30cb2a5359e1ec4bea60a466",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/tablecmds.c#L875-L878"
}
sources · src.call.42P07.19ee2522385544dc7ceb62bb
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 17376-17381",
  "path": "src/backend/commands/tablecmds.c",
  "position": 5,
  "sha256": "422dc8e833df4940755973c757e338295822ba3e4c7266c40669f49f96eb15a9",
  "source_id": "src.call.42P07.19ee2522385544dc7ceb62bb",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/tablecmds.c#L17376-L17381"
}
sources · src.calls.REL_18_6.42P07
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "raw/calls/REL_18_6.jsonl",
  "position": 6,
  "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
  "source_id": "src.calls.REL_18_6.42P07",
  "tag": "",
  "url": ""
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:e6a465ae20f643c366ded28a631186b4fafd6e9e4d633a10e9912ad276a83684

正文语言: zh-Hans · english-manuals:e6a465ae20f643c366ded28a631186b4fafd6e9e4d633a10e9912ad276a83684