42702
Read PG 18 manual ↗ambiguous_column
- SQLSTATE
- 42702
- Condition name
- ambiguous_column
- Class
- Syntax Error or Access Rule Violation
- Source macro
- ERRCODE_AMBIGUOUS_COLUMN
- Evidence
- Observed at runtime in the source evidence
English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗
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.
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.
CREATE TABLE syntax_schema.left_table (id integer);
CREATE TABLE syntax_schema.right_table (id integer);
INSERT INTO syntax_schema.left_table VALUES (1);
INSERT INTO syntax_schema.right_table VALUES (1);
SELECT id FROM syntax_schema.left_table, syntax_schema.right_table;
SELECT syntax_schema.left_table.id FROM syntax_schema.left_table, syntax_schema.right_table;
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.
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.
Source evidence
Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.
42702 is the ambiguous_column condition in Class 42.
Method: Read fixed errcodes.txt and the locked catalogue metadata.
Limits: Directory identity does not identify every backend path.
The fixed source calls for 42702 include the mechanism and message boundary selected for this page.
Method: Trace the resolved REL_18_6 and REL_10_23 source call records at the locked commits.
Limits: Other calls can use the same SQLSTATE with different context or dynamic fields.
The selected ambiguous_column case passed on isolated PostgreSQL 18.6 and 10.21 targets.
Method: Run the shared registry case and inspect structured diagnostics, state/recovery assertions, and cleanup.
Limits: This covers the selected case and targets only; it does not generalize to all drivers or intermediate releases.
The locked catalogue records 42702; runtime scope is limited to the selected targets.
Method: Read generated facts and selected summaries.
Limits: Definition presence is not an exact behavioral introduction.
- src/backend/utils/errcodes.txt · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 raw/calls/REL_18_6.jsonl· ·raw/calls/REL_10_23.jsonl· ·- src/backend/parser/parse_relation.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_relation.c · REL_10_23 ·
02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4 verify/cases/42702/cases.json· ·verify/cases/42702/snippets.json· ·
Message templates
explicit ERROR · message.ambiguous-column
Primary
column reference "%s" is ambiguous
Reproduction & repair cases
ambiguous_column · PG 10, 18
Preconditions
- A runner-owned disposable target is provisioned.
Trigger: Join two tables that both expose id and select id without qualification.
Expected assertions
- SQLSTATE is 42702 with the ambiguous-reference diagnostic
- The session remains IDLE
- Qualifying the column returns the intended row
Repair: Qualify the column with its table or alias and verify the intended source.
Cleanup: Drop the case schema with an owner connection.
Recorded runtime evidence
18.6 (Homebrew) · passed
Run: 42702-syntax-latest1
{
"diagnostic": {
"text": "column reference \"id\" is ambiguous\nLINE 1: SELECT id FROM \"c42702_ambiguous_column\".\"left_table\", \"c427...\n ^",
"context": null,
"severity": "ERROR",
"sqlstate": "42702",
"table_name": null,
"column_name": null,
"schema_name": null,
"source_file": "parse_relation.c",
"source_line": "964",
"message_hint": null,
"datatype_name": null,
"exception_type": "AmbiguousColumn",
"internal_query": null,
"message_detail": null,
"constraint_name": null,
"message_primary": "column reference \"id\" is ambiguous",
"source_function": "colNameToVar",
"internal_position": null,
"statement_position": "8",
"severity_nonlocalized": "ERROR"
},
"repair_value": 1,
"failed_status": "IDLE",
"repair_status": "IDLE",
"connection_autocommit": true
}10.21 (Debian 10.21-1.pgdg90+1) · passed
Run: 42702-syntax-pg10
{
"diagnostic": {
"text": "column reference \"id\" is ambiguous\nLINE 1: SELECT id FROM \"c42702_ambiguous_column\".\"left_table\", \"c427...\n ^",
"context": null,
"severity": "ERROR",
"sqlstate": "42702",
"table_name": null,
"column_name": null,
"schema_name": null,
"source_file": "parse_relation.c",
"source_line": "791",
"message_hint": null,
"datatype_name": null,
"exception_type": "AmbiguousColumn",
"internal_query": null,
"message_detail": null,
"constraint_name": null,
"message_primary": "column reference \"id\" is ambiguous",
"source_function": "colNameToVar",
"internal_position": null,
"statement_position": "8",
"severity_nonlocalized": "ERROR"
},
"repair_value": 1,
"failed_status": "IDLE",
"repair_status": "IDLE",
"connection_autocommit": true
}Definition snapshot: english-manuals:78b4011f257427681038ef4aeae… · English manual source