↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / SQLSTATE

42P07 — Duplicate table or relation definition

42P07 (duplicate_table) covers relation-name collisions, conditional skips, and inheritance graph checks. Identify the operation before repairing it.

English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

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

Definition PG 18

42P07 — Duplicate table or relation definition

At a glance {#at-a-glance}

42P07 (duplicate_table) covers relation-name collisions, conditional skips, and inheritance graph checks. Identify the operation before repairing it.

Meaning {#meaning}

Core 18.6 paths report relation "%s" already exists for table, sequence, index, and CREATE TABLE AS. These object kinds share the pg_class relation namespace, so a same-name object of another relation kind can be the collision. The index path with IF NOT EXISTS reports NOTICE relation "%s" already exists, skipping and returns without checking that the existing index has the requested definition. Inheritance reuses the code for repeated parents and for circular inheritance not allowed with DETAIL "%s" is already a child of "%s".

Diagnosis {#diagnosis}

Capture message, severity, DETAIL, statement, schema, and relation kind. For a name collision, inspect pg_class joined to pg_namespace and include sequences, indexes, tables, views, and materialized views in the search. For an IF NOT EXISTS NOTICE, inspect the existing object's owner, persistence, columns, indexes, and options before treating the migration as satisfied; the source guard is name-based. For inheritance messages, inspect pg_inherits, resolve the complete parent list, and distinguish a duplicate parent from a cycle.

Response {#response}

Use idempotent DDL only when the existing definition is acceptable; otherwise choose a deliberate name or an object-specific migration. A relation-name collision may require adopting the existing object or changing the intended name, while a repeated-parent error requires removing the duplicate parent entry. A cycle requires breaking the parent graph and then verifying pg_inherits; renaming alone cannot repair it. Recover an explicit-transaction ERROR with a savepoint rollback or transaction rollback before catalog checks; a NOTICE path does not require that recovery.

Messages {#messages}

Representative variants are:

| Path | Severity | Primary | DETAIL | | --- | --- | --- | --- | | relation name collision | ERROR | relation "%s" already exists | none | | index IF NOT EXISTS collision | NOTICE | relation "%s" already exists, skipping | none | | repeated inheritance parent | ERROR | relation "%s" would be inherited from more than once | none | | circular inheritance | ERROR | circular inheritance not allowed | "%s" is already a child of "%s". |

Versions {#versions}

From 7.4 through 18.6 and 19beta3; that catalogue range is not a precise introduction claim. The selected 18.6 paths cover relation-name lookup, index IF NOT EXISTS, repeated inheritance parents, and circularity; runtime was not run.

Related {#related}

Sources {#sources}

  • src.errcodes.42P07.18.6 — src/backend/utils/errcodes.txt line 383, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba (source).

  • src.call.42P07.694fcfd426e95ce13263fb9a — src/backend/catalog/heap.c lines 1194-1196, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 e720ee58279590793edd0985b3c910970ef56e7361b8ef92e245370587e02a0e (source).

  • src.call.42P07.38d8697cf62c00c05657a6d4 — src/backend/catalog/index.c lines 898-901, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 98a4156a5c21ae856a3b583b633cdeb578a5b69910386c9f166d69fcb04ba2d0 (source).

  • src.call.42P07.30cb2a5359e1ec4bea60a466 — src/backend/commands/tablecmds.c lines 875-878, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 422dc8e833df4940755973c757e338295822ba3e4c7266c40669f49f96eb15a9 (source).

  • src.call.42P07.19ee2522385544dc7ceb62bb — src/backend/commands/tablecmds.c lines 17376-17381, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 422dc8e833df4940755973c757e338295822ba3e4c7266c40669f49f96eb15a9 (source).

  • src.calls.REL_18_6.42P07 — resolved core call groups; SHA-256 9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf.

  • authored evidence — source claims, message roles, and runtime boundary.

Compare versions

SQLSTATE evidence and recorded runtime versions

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": ""
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:e6a465ae20f643c366ded28a631186b4fafd6e9e4d633a10e9912ad276a83684

Text language: en · english-manuals:e6a465ae20f643c366ded28a631186b4fafd6e9e4d633a10e9912ad276a83684