Skip to content

42P09 — Ambiguous table alias

PostgreSQL SQLSTATE 42P09: Ambiguous table alias (ambiguous_alias), source-backed diagnosis and recovery guidance.

42P09 — Ambiguous table alias

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.

Field Value
SQLSTATE 42P09
Condition ambiguous_alias
Status active
Known present by 7.4
Locked snapshots 9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3
Macros ERRCODE_AMBIGUOUS_ALIAS
Aliases

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.