↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

42P09 — 表别名不明确

一个表引用对应多个关系命名空间项。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

aliases
未知
class name
Syntax Error or Access Rule Violation
condition name
ambiguous_alias
lang
en
sqlstate
42P09

版本定义 PG 18

42P09 — 表别名不明确

速览 {#at-a-glance}

42P09(ambiguous_alias)是解析阶段的 ERROR:一个可见表引用对应多个关系命名空间项。它发生在执行前,并有文本别名和关系 OID 两条路径。

含义 {#meaning}

文本引用由 scanNameSpaceForRefname 比较可见命名空间别名,发现第二个可见匹配时报告 table reference "%s" is ambiguous。仅列项和非活动 LATERAL 作用域中的 lateral-only 项会被排除。scanNameSpaceForRelid 另一条路径按 OID 匹配无别名关系 RTE,同一关系出现多次时报告 table reference %u is ambiguous。两条路径都带解析位置,且不同于列歧义。

诊断 {#diagnosis}

检查 FROM/JOIN 树、别名、子查询/CTE 可见性和 LATERAL 作用域。若主消息带引号名称,查找重复的可见别名;若带 OID,查找重复的无别名同一关系 RTE。还要检查连接别名是否隐藏内部命名空间,或 LATERAL 子查询是否同时暴露两个别名。search_path 可能影响前面的关系查找,但不能作为已存在重复解析项的通用修复。

处理 {#response}

给可见关系设置有意义且不同的别名,并通过别名限定引用,或从查询构造器删除多余关系。保留有意的 LATERAL 作用域,修改后核对连接基数。不要把 42P09 当作 42P01(关系不存在)或 42702(列歧义),也不要反复提交相同文本。解析 ERROR 若发生在显式事务中,应回滚到保存点或回滚事务再继续。

消息变体 {#messages}

选定变体均为 ERROR:

| 解析路径 | 主消息 | | --- | --- | | 重复的可见别名/名称 | table reference "%s" is ambiguous | | 重复的无别名关系 OID | table reference %u is ambiguous |

两者都附带解析位置;%s 和 %u 是源码中的动态字段。

版本 {#versions}

目录范围从 7.4 到 18.6、19beta3,不是精确的功能引入判断。选定的是 18.6 固定文本别名和内部 OID 源码路径,未运行数据库。

相关 {#related}

来源 {#sources}

  • src.errcodes.42P09.18.6 — src/backend/utils/errcodes.txt line 389,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba(源码)。

  • src.call.42P09.ed0c1b7f7e4bd90cb2068e17 — src/backend/parser/parse_relation.c lines 224-228,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 0d9c88f4a8def4c2d982c33f13208590e21ecf5e6f8cd9d7faa223dc771c9a9a(源码)。

  • src.call.42P09.171afa1503a4e198e620e1b5 — src/backend/parser/parse_relation.c lines 271-275,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 0d9c88f4a8def4c2d982c33f13208590e21ecf5e6f8cd9d7faa223dc771c9a9a(源码)。

  • src.calls.REL_18_6.42P09 — 固定本地核心调用扫描;SHA-256 9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf。

  • 作者证据 — 记录源码断言、消息角色和运行边界。

比较版本

SQLSTATE 证据与已记录的运行版本

claims · identity.class-and-condition
{
  "claim_id": "identity.class-and-condition",
  "limits": "Identity does not enumerate all source branches or client failures.",
  "method": "Read fixed REL_18_6 errcodes.txt and locked facts.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.42P09.18.6"
  ],
  "statement": "42P09 is the ambiguous_alias condition in Class 42."
}
claims · mechanism.selected-source-path
{
  "claim_id": "mechanism.selected-source-path",
  "limits": "Representative confirmed core paths only; not exhaustive historical or extension coverage.",
  "method": "Read complete resolved REL_18_6 report groups and message roles.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.call.42P09.ed0c1b7f7e4bd90cb2068e17",
    "src.call.42P09.171afa1503a4e198e620e1b5"
  ],
  "statement": "scanNameSpaceForRefname compares visible aliases and reports `table reference \"%s\" is ambiguous` on a duplicate visible alias; scanNameSpaceForRelid reports `table reference %u is ambiguous` when an unaliased relation RTE with the same OID appears more than once. Lateral-only and column-only visibility guards are applied, and both paths are separate from column ambiguity."
}
claims · versions.catalogue-boundary
{
  "claim_id": "versions.catalogue-boundary",
  "limits": "First observed release is a lower bound, not precise behavioral introduction.",
  "method": "Read locked catalogue facts and definition snapshots.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.42P09.18.6"
  ],
  "statement": "From 7.4 through 18.6 and 19beta3; this catalogue range is not a precise introduction claim. The selected named-alias and internal-OID branches are fixed 18.6 source paths and runtime was not run."
}
messages · message.variant-1
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-1",
  "path": "",
  "position": 0,
  "raw": {
    "detail_templates": [],
    "hint_templates": [],
    "id": "message.variant-1",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "table reference \"%s\" is ambiguous",
    "roles": [
      {
        "role": "errmsg",
        "template": "table reference \"%s\" is ambiguous"
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P09.ed0c1b7f7e4bd90cb2068e17"
    ],
    "sqlstate": "42P09"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P09.ed0c1b7f7e4bd90cb2068e17"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "table reference \" \" is ambiguous",
      "position": 0,
      "role": "",
      "template": "table reference \"%s\" is ambiguous"
    }
  ]
}
messages · message.variant-2
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-2",
  "path": "",
  "position": 1,
  "raw": {
    "detail_templates": [],
    "hint_templates": [],
    "id": "message.variant-2",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "table reference %u is ambiguous",
    "roles": [
      {
        "role": "errmsg",
        "template": "table reference %u is ambiguous"
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P09.171afa1503a4e198e620e1b5"
    ],
    "sqlstate": "42P09"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P09.171afa1503a4e198e620e1b5"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "table reference is ambiguous",
      "position": 0,
      "role": "",
      "template": "table reference %u is ambiguous"
    }
  ]
}
sources · src.errcodes.42P09.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "line 389",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.42P09.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L389"
}
sources · src.call.42P09.ed0c1b7f7e4bd90cb2068e17
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 224-228",
  "path": "src/backend/parser/parse_relation.c",
  "position": 1,
  "sha256": "0d9c88f4a8def4c2d982c33f13208590e21ecf5e6f8cd9d7faa223dc771c9a9a",
  "source_id": "src.call.42P09.ed0c1b7f7e4bd90cb2068e17",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_relation.c#L224-L228"
}
sources · src.call.42P09.171afa1503a4e198e620e1b5
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 271-275",
  "path": "src/backend/parser/parse_relation.c",
  "position": 2,
  "sha256": "0d9c88f4a8def4c2d982c33f13208590e21ecf5e6f8cd9d7faa223dc771c9a9a",
  "source_id": "src.call.42P09.171afa1503a4e198e620e1b5",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_relation.c#L271-L275"
}
sources · src.calls.REL_18_6.42P09
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "raw/calls/REL_18_6.jsonl",
  "position": 3,
  "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
  "source_id": "src.calls.REL_18_6.42P09",
  "tag": "",
  "url": ""
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:9dbdfaa4a8900391be576fd8f113b077efbbb62bc24d4704dd79142d8d2de8a5

正文语言: zh-Hans · english-manuals:9dbdfaa4a8900391be576fd8f113b077efbbb62bc24d4704dd79142d8d2de8a5