选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / 错误代码 / Class 42 语法错误或访问规则冲突

42712 duplicate_alias

重复别名

ERROR 已实测 参考 实测通过

条件名
duplicate_alias
宏名称
ERRCODE_DUPLICATE_ALIAS
启用版本
7.4
状态
活跃

版本覆盖

速览

42712duplicate_alias(重复别名):同一查询命名空间重复使用表别名。解析器拒绝两个都叫 duplicate_aliasVALUES 表项。

含义

别名属于查询命名空间,第二个同名范围表在执行前就有歧义。它不同于重复物理对象 42710 和重复输出列名。检查 FROM/JOIN/CTE/子查询别名;自动提交错误后为 IDLE

诊断

检查 FROM、JOIN、CTE 和子查询的每个别名,也检查生成 SQL 引入的别名。冲突发生在当前查询命名空间,search_path 或修改基础表名不是诊断方向。

处理

给范围表使用不同别名并限定列。改基础表名或 search_path 不能修复当前查询。显式事务中的解析失败会使事务进入 INERROR,应先回滚或回到合适的 savepoint 再重试;本案例的自动提交路径回到 IDLE

可复现案例

在一次性实例上执行过的场景。其中 1 个附有可执行 SQL,正文相应小节里给出。

duplicate_table_alias PG 10 / 18 有 SQL

前置条件

  • A runner-owned disposable target is provisioned.

触发

Use the same table alias for two VALUES relations in one SELECT.

断言

  • SQLSTATE is 42712 with the duplicate table-name message
  • The failed autocommit session remains IDLE
  • Distinct aliases return the two input values

处置

Give each range-table entry a distinct alias; do not rename unrelated catalog objects.

清理

Close the runner connection; no persistent objects are created.

实测诊断

固定解析器组是 ERROR,主模板为 table name "%s" specified more than once,没有 DETAIL/HINT。

报文模板

源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。

主消息 table name "%s" specified more than once

来源:src/backend/parser/parse_relation.c @ REL_18_6 · src/backend/parser/parse_relation.c @ REL_10_23

代表案例

案例让两个单行 VALUES 表项先同名,再改成 left_alias/right_alias 并断言两个值。

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

选定的 18.6 与 10.21 运行均通过 SQLSTATE、严重级别、状态/恢复、修复、清理和一次性实例停止断言。详见 案例 JSON作者证据;私有清单和注册表哈希也记录在其中。

版本

锁定目录从 7.4 存在边界起包含该条件并列出相关快照。选定自然案例已在 PostgreSQL 18.6 与 10.21 通过;这是有界观察,不能推断所有中间版本或所有源码分支。

来源

证据

断言

每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。

  • 42712 is the duplicate_alias condition in Class 42.

    核实方式Read fixed errcodes.txt and locked catalogue metadata.

    不覆盖Identity does not identify every backend call that can reuse this SQLSTATE.

    来源src/backend/utils/errcodes.txt

  • The selected duplicate_table_alias follows a resolved PostgreSQL source-call group; other branches can use different dynamic fields.

    核实方式Trace the REL_18_6 and REL_10_23 source-call records at the locked commits.

    不覆盖This is one mechanism boundary, not an exhaustive inventory of the code.

    来源src/backend/parser/parse_relation.c · src/backend/parser/parse_relation.c

  • The selected duplicate_table_alias passed on isolated PostgreSQL 18.6 and 10.21 targets.

    核实方式Run the shared SQL registry and inspect SQLSTATE, severity, state, repair, cleanup, and target stop.

    不覆盖Scope is limited to these statements, psycopg, and two versions.

    来源verify/cases/42712/cases.json · verify/cases/42712/snippets.json

  • The locked catalogue records 42712 from the 7.4 presence bound through the listed snapshots; runtime scope is 18.6 and 10.21.

    核实方式Read generated facts, fixed calls, and selected summaries.

    不覆盖Definition presence is not an exact behavioral introduction; two runtime versions do not prove every intermediate behavior.

    来源src/backend/utils/errcodes.txt · raw/calls/REL_18_6.jsonl · raw/calls/REL_10_23.jsonl

运行记录

目标服务器版本结果覆盖案例
latest 18.6 (Homebrew) passed duplicate_table_alias
pg10 10.21 (Debian 10.21-1.pgdg90+1) passed duplicate_table_alias

同类错误代码

Class 42 语法错误或访问规则冲突 下的其他成员。