42702 — ambiguous_column
42702
At a glance
SQLSTATE 42702 is ambiguous_column in Class 42. 42702 is ambiguous_column. The selected join exposes id from two real tables and an unqualified SELECT id reports column reference "%s" is ambiguous.
| Field | Value |
|---|---|
| SQLSTATE | 42702 |
| Condition | ambiguous_column |
| 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_COLUMN |
| Aliases | — |
Meaning
42702 is ambiguous_column. In colNameToVar, PostgreSQL scans the visible namespace for an unqualified name. Once two visible range-table entries produce a match in the same lookup, the parser raises ERROR column reference "%s" is ambiguous; the selected join exposes id from both real tables. The branch is about name resolution, before execution or row values can disambiguate it.
Diagnosis
Inspect aliases, CTEs, join inputs, lateral visibility, and every relation contributing the name in the current query scope. An unqualified name can be ambiguous even when the two columns contain the same value; PostgreSQL must resolve the source before executing the query. This is parse-time name resolution, so the selected autocommit session remains IDLE; it is distinct from 42703 where no matching column exists. An explicit transaction still follows the usual statement-ERROR transaction-state rule.
Response
Qualify the intended column with a stable table alias (or remove the unintended relation from the scope), then verify the returned row. Do not solve the ambiguity by relying on join order or equal values. If generated SQL introduces aliases or CTEs, make the qualification part of the query-builder contract and test the selected source column.
Messages
The selected parse_relation.c branch emits an explicit ERROR with primary column reference "%s" is ambiguous; %s is the unresolved column name and parser position is contextual. A client exception without the server SQLSTATE and primary is not sufficient to claim 42702.
Representative case
The page uses the same statements as the runner registry. Generated names such as syntax_schema and syntax_role are replaced by disposable runner values when executed.
The selected 18.6 run reports the structured diagnostic and passes the repair assertions; the 10.21 run passes the same case-specific checks. The downloadable case and evidence projections are 42702 case JSON and authored evidence. The runner manifest is verify/cases/42702/cases.json, and the page SQL is checked against its shared registry.
Versions
The selected natural runtime scope is PostgreSQL 18.6 and 10.21; it does not infer behavior for every intermediate release.
Related
Sources
src.errcodes.18.6— fixederrcodes.txtdefinition at commit724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-2566e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba(source).src.ambiguous-column.18.6—src/backend/parser/parse_relation.catREL_18_6commit724edf9bde9d356724ad384a2e196edc3c9f80f7; fixed blob SHA-2560d9c88f4a8def4c2d982c33f13208590e21ecf5e6f8cd9d7faa223dc771c9a9a(source).src.ambiguous-column.10.23—src/backend/parser/parse_relation.catREL_10_23commit02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4; fixed blob SHA-256a34f40fc93fa5df0015fe5af5ee7761ccba2d16a791cda69ae07848ed27616b5(source).src.calls.REL_18_6/src.calls.REL_10_23— fixed call scans, SHA-2569ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf/00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c.