42712
Read PG 18 manual ↗duplicate_alias
- SQLSTATE
- 42712
- Condition name
- duplicate_alias
- Class
- Syntax Error or Access Rule Violation
- Source macro
- ERRCODE_DUPLICATE_ALIAS
- 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
42712 is duplicate_alias: a query namespace assigns the same table alias more than once. The parser rejects two VALUES range-table entries named duplicate_alias.
Meaning
Aliases are query names, so the second range-table entry is ambiguous before execution. This differs from a duplicate physical object (42710) and from repeated output column labels. Inspect every FROM/JOIN/CTE/subquery alias. The selected autocommit error leaves IDLE.
Diagnosis
Inspect every FROM, JOIN, CTE, and subquery alias, including aliases introduced by generated SQL. The duplicate is in the current query namespace, so search_path or renaming a base table is not the diagnosis.
Response
Give each range-table entry a distinct alias and qualify references. Renaming a base table or changing search_path does not repair the current query. In an explicit transaction, the failed parse leaves INERROR; roll back or return to a suitable savepoint before retrying. The selected autocommit path returns to IDLE.
Observed diagnostics
The fixed parser group is explicit ERROR with primary table name "%s" specified more than once and no detail or hint.
Representative case
The case uses two one-row VALUES relations with the same alias, then left_alias and right_alias, asserting both values.
SELECT * FROM (VALUES (1)) AS duplicate_alias(value), (VALUES (2)) AS duplicate_alias(value);
SELECT left_alias.value, right_alias.value FROM (VALUES (1)) AS left_alias(value), (VALUES (2)) AS right_alias(value);
The selected 18.6 and 10.21 runs passed SQLSTATE, severity, state/recovery, repair, cleanup, and isolated-target stop assertions. See case JSON and authored evidence; private manifest and registry hashes are recorded there.
Versions
The locked catalogue contains this condition from the 7.4 presence bound through the listed snapshots. The selected natural case passed on PostgreSQL 18.6 and 10.21; that bounded result does not infer every intermediate release or every source branch.
Sources
src.errcodes.REL_18_6— fixed definition at724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-2566e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba(source).src.duplicate-alias.18.6—src/backend/parser/parse_relation.clines 471–474 at724edf9bde9d356724ad384a2e196edc3c9f80f7; blob SHA-2560d9c88f4a8def4c2d982c33f13208590e21ecf5e6f8cd9d7faa223dc771c9a9a(source).src.duplicate-alias.10.23—src/backend/parser/parse_relation.clines 417–420 at02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4; blob SHA-256a34f40fc93fa5df0015fe5af5ee7761ccba2d16a791cda69ae07848ed27616b5(source).src.calls.REL_18_6/src.calls.REL_10_23— fixed call scans, SHA-2569ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf/00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c.manifest.42712/snippet-registry.42712— hashes are recorded inevidence/42712.jsonand each runtime record.
Source evidence
Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.
42712 is the duplicate_alias condition in Class 42.
Method: Read fixed errcodes.txt and locked catalogue metadata.
Limits: Identity does not identify every backend call that can reuse this SQLSTATE.
The selected duplicate_table_alias follows a resolved PostgreSQL source-call group; other branches can use different dynamic fields.
Method: Trace the REL_18_6 and REL_10_23 source-call records at the locked commits.
Limits: This is one mechanism boundary, not an exhaustive inventory of the code.
The selected duplicate_table_alias passed on isolated PostgreSQL 18.6 and 10.21 targets.
Method: Run the shared SQL registry and inspect SQLSTATE, severity, state, repair, cleanup, and target stop.
Limits: Scope is limited to these statements, psycopg, and two versions.
The locked catalogue records 42712 from the 7.4 presence bound through the listed snapshots; runtime scope is 18.6 and 10.21.
Method: Read generated facts, fixed calls, and selected summaries.
Limits: Definition presence is not an exact behavioral introduction; two runtime versions do not prove every intermediate behavior.
src.errcodes.REL_18_6 src.calls.REL_18_6 src.calls.REL_10_23
- 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/42712/cases.json· ·verify/cases/42712/snippets.json· ·
Message templates
explicit ERROR · message.duplicate_table_alias
Primary
table name "%s" specified more than once
Reproduction & repair cases
duplicate_table_alias · PG 10, 18
Preconditions
- A runner-owned disposable target is provisioned.
Trigger: Use the same table alias for two VALUES relations in one SELECT.
Expected assertions
- SQLSTATE is 42712 with the duplicate table-name message
- The failed autocommit session remains IDLE
- Distinct aliases return the two input values
Repair: Give each range-table entry a distinct alias; do not rename unrelated catalog objects.
Cleanup: Close the runner connection; no persistent objects are created.
Recorded runtime evidence
18.6 (Homebrew) · passed
Run: syntax2-42712-latest
{
"diagnostic": {
"text": "table name \"duplicate_alias\" specified more than once",
"context": null,
"severity": "ERROR",
"sqlstate": "42712",
"table_name": null,
"column_name": null,
"schema_name": null,
"source_file": "parse_relation.c",
"source_line": "474",
"message_hint": null,
"datatype_name": null,
"exception_type": "DuplicateAlias",
"internal_query": null,
"message_detail": null,
"constraint_name": null,
"message_primary": "table name \"duplicate_alias\" specified more than once",
"source_function": "checkNameSpaceConflicts",
"internal_position": null,
"statement_position": null,
"severity_nonlocalized": "ERROR"
},
"repair_rows": [
[
1,
2
]
],
"failed_status": "IDLE",
"repair_status": "IDLE",
"connection_autocommit": true
}10.21 (Debian 10.21-1.pgdg90+1) · passed
Run: syntax2-42712-pg10
{
"diagnostic": {
"text": "table name \"duplicate_alias\" specified more than once",
"context": null,
"severity": "ERROR",
"sqlstate": "42712",
"table_name": null,
"column_name": null,
"schema_name": null,
"source_file": "parse_relation.c",
"source_line": "420",
"message_hint": null,
"datatype_name": null,
"exception_type": "DuplicateAlias",
"internal_query": null,
"message_detail": null,
"constraint_name": null,
"message_primary": "table name \"duplicate_alias\" specified more than once",
"source_function": "checkNameSpaceConflicts",
"internal_position": null,
"statement_position": null,
"severity_nonlocalized": "ERROR"
},
"repair_rows": [
[
1,
2
]
],
"failed_status": "IDLE",
"repair_status": "IDLE",
"connection_autocommit": true
}Definition snapshot: english-manuals:b453a67a05a49ab5643f3a06655… · English manual source