select open change scope Open full search

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

SQLSTATE / CLASS 42 · SYNTAX ERROR OR ACCESS RULE VIOLATION

duplicate_table

SQLSTATE
42P07
Condition name
duplicate_table
Class
Syntax Error or Access Rule Violation
Source macro
ERRCODE_DUPLICATE_TABLE
Evidence
Source path confirmed
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>42P07 — Duplicate table or relation definition</h1>

At a glance

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

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

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

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

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

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.

Sources

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

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

  • src.call.42P07.38d8697cf62c00c05657a6d4src/backend/catalog/index.c lines 898-901, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 98a4156a5c21ae856a3b583b633cdeb578a5b69910386c9f166d69fcb04ba2d0 (source).
  • src.call.42P07.30cb2a5359e1ec4bea60a466src/backend/commands/tablecmds.c lines 875-878, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 422dc8e833df4940755973c757e338295822ba3e4c7266c40669f49f96eb15a9 (source).
  • src.call.42P07.19ee2522385544dc7ceb62bbsrc/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.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

42P07 is the duplicate_table condition in Class 42.

Method: Read fixed REL_18_6 errcodes.txt and locked facts.

Limits: Identity does not enumerate all source branches or client failures.

src.errcodes.42P07.18.6

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".`

Method: Read complete resolved REL_18_6 report groups and message roles.

Limits: Representative confirmed core paths only; not exhaustive historical or extension coverage.

src.call.42P07.694fcfd426e95ce13263fb9a src.call.42P07.38d8697cf62c00c05657a6d4 src.call.42P07.index-if-not-exists-guard src.call.42P07.30cb2a5359e1ec4bea60a466 src.call.42P07.19ee2522385544dc7ceb62bb

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.

Method: Read locked catalogue facts and definition snapshots.

Limits: First observed release is a lower bound, not precise behavioral introduction.

src.errcodes.42P07.18.6

Message templates

explicit ERROR · message.variant-1

Primary

relation "%s" already exists

Placeholders remain dynamic source fields; no concrete runtime value is claimed.

explicit NOTICE · message.variant-2

Primary

relation "%s" already exists, skipping

Placeholders remain dynamic source fields; no concrete runtime value is claimed.

explicit ERROR · message.variant-3

Primary

relation "%s" would be inherited from more than once

Placeholders remain dynamic source fields; no concrete runtime value is claimed.

explicit ERROR · message.variant-4

Primary

circular inheritance not allowed

Detail

"%s" is already a child of "%s".

Primary

"%s" is already a child of "%s".

Placeholders remain dynamic source fields; no concrete runtime value is claimed.

Reproduction & repair cases

No reproduction case is attached to this condition.

Recorded runtime evidence

No runtime observation is attached to this entry.

Definition snapshot: english-manuals:1ef1e22665706d4ea6669457f7b… · English manual source