↑↓ select↵ open⌫ change scopeOpen full search

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

Wiki / SQLSTATE

42P09 — Ambiguous table alias

42P09 (ambiguous_alias) is a parser ERROR when one visible table reference resolves to more than one relation namespace item. It occurs before execution and has separate named-alias and relation-OID paths.

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
ambiguous_alias
lang
en
sqlstate
42P09

Definition PG 18

42P09 — Ambiguous table alias

At a glance {#at-a-glance}

42P09 (ambiguous_alias) is a parser ERROR when one visible table reference resolves to more than one relation namespace item. It occurs before execution and has separate named-alias and relation-OID paths.

Meaning {#meaning}

For a textual reference, scanNameSpaceForRefname compares visible namespace aliases and raises table reference "%s" is ambiguous when a second match is visible. Column-only items and lateral-only items outside an active LATERAL scope are excluded. A separate scanNameSpaceForRelid path matches unaliased relation RTEs by OID and raises table reference %u is ambiguous when the same relation appears more than once. Both include parser position and are distinct from column ambiguity.

Diagnosis {#diagnosis}

Inspect the FROM/JOIN tree, alias names, subquery/CTE visibility, and LATERAL scope. If the primary includes a quoted name, find repeated visible aliases; if it includes an OID, look for repeated unaliased RTEs of that relation. Check whether a join alias hides an inner namespace or whether a LATERAL subquery makes both aliases visible. search_path can affect earlier relation lookup, but changing it is not a generic repair for a duplicate item already present in the parse namespace.

Response {#response}

Give each visible relation a deliberate alias, qualify references through that alias, or remove the redundant relation from the query builder. Preserve intentional LATERAL scope and verify join cardinality after the change. Do not treat 42P09 as 42P01 (missing relation) or 42702 (ambiguous column), and do not repeatedly submit identical text. If the parser ERROR occurred inside an explicit transaction, roll back to a savepoint or roll back the transaction before continuing.

Messages {#messages}

The selected variants are explicit ERRORs:

| Parser path | Primary | | --- | --- | | duplicate visible alias/name | table reference "%s" is ambiguous | | duplicate unaliased relation OID | table reference %u is ambiguous |

Both attach parser position; %s and %u are dynamic source fields.

Versions {#versions}

From 7.4 through 18.6 and 19beta3; that catalogue range is not a precise introduction claim. The selected named-alias and internal-OID branches are fixed 18.6 source paths, and runtime was not run.

Related {#related}

Sources {#sources}

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

  • src.call.42P09.ed0c1b7f7e4bd90cb2068e17 — src/backend/parser/parse_relation.c lines 224-228, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 0d9c88f4a8def4c2d982c33f13208590e21ecf5e6f8cd9d7faa223dc771c9a9a (source).

  • src.call.42P09.171afa1503a4e198e620e1b5 — src/backend/parser/parse_relation.c lines 271-275, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 0d9c88f4a8def4c2d982c33f13208590e21ecf5e6f8cd9d7faa223dc771c9a9a (source).

  • src.calls.REL_18_6.42P09 — 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.42P09.18.6"
  ],
  "statement": "42P09 is the ambiguous_alias 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.42P09.ed0c1b7f7e4bd90cb2068e17",
    "src.call.42P09.171afa1503a4e198e620e1b5"
  ],
  "statement": "scanNameSpaceForRefname compares visible aliases and reports `table reference \"%s\" is ambiguous` on a duplicate visible alias; scanNameSpaceForRelid reports `table reference %u is ambiguous` when an unaliased relation RTE with the same OID appears more than once. Lateral-only and column-only visibility guards are applied, and both paths are separate from column ambiguity."
}
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.42P09.18.6"
  ],
  "statement": "From 7.4 through 18.6 and 19beta3; this catalogue range is not a precise introduction claim. The selected named-alias and internal-OID 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": "table reference \"%s\" is ambiguous",
    "roles": [
      {
        "role": "errmsg",
        "template": "table reference \"%s\" is ambiguous"
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P09.ed0c1b7f7e4bd90cb2068e17"
    ],
    "sqlstate": "42P09"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P09.ed0c1b7f7e4bd90cb2068e17"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "table reference \" \" is ambiguous",
      "position": 0,
      "role": "",
      "template": "table reference \"%s\" is ambiguous"
    }
  ]
}
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": "table reference %u is ambiguous",
    "roles": [
      {
        "role": "errmsg",
        "template": "table reference %u is ambiguous"
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P09.171afa1503a4e198e620e1b5"
    ],
    "sqlstate": "42P09"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P09.171afa1503a4e198e620e1b5"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "table reference is ambiguous",
      "position": 0,
      "role": "",
      "template": "table reference %u is ambiguous"
    }
  ]
}
sources · src.errcodes.42P09.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "line 389",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.42P09.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L389"
}
sources · src.call.42P09.ed0c1b7f7e4bd90cb2068e17
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 224-228",
  "path": "src/backend/parser/parse_relation.c",
  "position": 1,
  "sha256": "0d9c88f4a8def4c2d982c33f13208590e21ecf5e6f8cd9d7faa223dc771c9a9a",
  "source_id": "src.call.42P09.ed0c1b7f7e4bd90cb2068e17",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_relation.c#L224-L228"
}
sources · src.call.42P09.171afa1503a4e198e620e1b5
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 271-275",
  "path": "src/backend/parser/parse_relation.c",
  "position": 2,
  "sha256": "0d9c88f4a8def4c2d982c33f13208590e21ecf5e6f8cd9d7faa223dc771c9a9a",
  "source_id": "src.call.42P09.171afa1503a4e198e620e1b5",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_relation.c#L271-L275"
}
sources · src.calls.REL_18_6.42P09
{
  "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.42P09",
  "tag": "",
  "url": ""
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:9dbdfaa4a8900391be576fd8f113b077efbbb62bc24d4704dd79142d8d2de8a5

Text language: en · english-manuals:9dbdfaa4a8900391be576fd8f113b077efbbb62bc24d4704dd79142d8d2de8a5