# 42712 — Duplicate alias

> PostgreSQL SQLSTATE 42712: Duplicate alias (duplicate_alias), source-backed diagnosis and recovery guidance.
---

# 42712 — Duplicate alias

## At a glance {#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`.

<!-- BEGIN SQLSTATE FACTS: generated by scripts/generate.py; do not edit -->

| Field | Value |
| --- | --- |
| SQLSTATE | `42712` |
| Condition | `duplicate_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_DUPLICATE_ALIAS` |
| Aliases | `—` |

<!-- source facts: data/errcodes/42712.json -->
<!-- END SQLSTATE FACTS -->

## Meaning {#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 {#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 {#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 {#messages}

The fixed parser group is explicit `ERROR` with primary `table name "%s" specified more than once` and no detail or hint.

## Representative case {#case}

The case uses two one-row VALUES relations with the same alias, then `left_alias` and `right_alias`, asserting both values.

<!-- BEGIN SQLSTATE SNIPPET: duplicate_table_alias -->

```sql
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);
```

<!-- END SQLSTATE SNIPPET -->

The selected 18.6 and 10.21 runs passed SQLSTATE, severity, state/recovery, repair, cleanup, and isolated-target stop assertions. See [`case JSON`](../data/cases/42712.json) and [`authored evidence`](../data/evidence/42712.json); private manifest and registry hashes are recorded there.

## Versions {#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.

## Related {#related}

- [`42703`](../42703/)
- [`42725`](../42725/)

## Sources {#sources}

- `src.errcodes.REL_18_6` — fixed definition at `724edf9bde9d356724ad384a2e196edc3c9f80f7`; SHA-256 `6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L1-L1)).
- `src.duplicate-alias.18.6` — `src/backend/parser/parse_relation.c` lines 471–474 at `724edf9bde9d356724ad384a2e196edc3c9f80f7`; blob SHA-256 `0d9c88f4a8def4c2d982c33f13208590e21ecf5e6f8cd9d7faa223dc771c9a9a` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_relation.c#L471-L474)).
- `src.duplicate-alias.10.23` — `src/backend/parser/parse_relation.c` lines 417–420 at `02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4`; blob SHA-256 `a34f40fc93fa5df0015fe5af5ee7761ccba2d16a791cda69ae07848ed27616b5` ([source](https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/backend/parser/parse_relation.c#L417-L420)).
- `src.calls.REL_18_6` / `src.calls.REL_10_23` — fixed call scans, SHA-256 `9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf` / `00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c`.
- `manifest.42712` / `snippet-registry.42712` — hashes are recorded in `evidence/42712.json` and each runtime record.
