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

ambiguous_alias

SQLSTATE
42P09
Condition name
ambiguous_alias
Class
Syntax Error or Access Rule Violation
Source macro
ERRCODE_AMBIGUOUS_ALIAS
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>42P09 — Ambiguous table alias</h1>

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

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

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

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

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

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.

Sources

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

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

  • src.call.42P09.171afa1503a4e198e620e1b5src/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.

Source evidence

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

42P09 is the ambiguous_alias 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.42P09.18.6

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.

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.42P09.ed0c1b7f7e4bd90cb2068e17 src.call.42P09.171afa1503a4e198e620e1b5

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.

Method: Read locked catalogue facts and definition snapshots.

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

src.errcodes.42P09.18.6

Message templates

explicit ERROR · message.variant-1

Primary

table reference "%s" is ambiguous

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

explicit ERROR · message.variant-2

Primary

table reference %u is ambiguous

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:2a81f795605b7ce07446cb38eb7… · English manual source