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

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

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

42703 undefined_column

未定义列

ERROR 已实测 详解 实测通过

条件名
undefined_column
宏名称
ERRCODE_UNDEFINED_COLUMN
启用版本
7.4
状态
活跃

版本覆盖

速览

SQLSTATE 42703 是 Class 42 中的 undefined_column42703 表示未定义列。选定查询在真实表上引用 missing_column,报告 column "%s" does not exist;改为已定义的 id 后成功。

含义

42703 表示未定义列。当关系已经解析出来、但引用的列不在可见查询范围内时,errorMissingColumn 会在 range table 中寻找有用建议并发出 ERRORcolumn "%s" does not exist(如果指定了关系,也可能使用限定形式)。选定查询在真实表上引用 missing_column,改为已定义的 id 后成功。

诊断

检查准确关系、别名、解析范围、带引号的拼写/大小写和迁移版本。如果解析器找到接近候选列,可能追加 HINT;选定路径没有 HINT。解析器在执行前报告错误,自动提交会话仍为 IDLE;显式 BEGIN 中会让事务进入 INERROR,必须 ROLLBACK 或回滚到合适保存点后再重试。要把缺列与 42P01(未限定关系不存在)、3F000(schema/创建 namespace 不存在)以及 42702(多个可见列匹配)区分开。

处理

修正列名或迁移后针对预期关系重新执行。如果应用支持多个 schema 或版本,应限定关系并先部署匹配的迁移。带引号且大小写不同的标识符是不同名称;修改应用 SQL 前应通过目录或 introspection 确认已部署的拼写。

可复现案例

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

undefined_column PG 10 / 18 有 SQL

前置条件

  • A runner-owned disposable target is provisioned.

触发

Select a column name that is absent from a real table.

断言

  • SQLSTATE is 42703 with the undefined-column diagnostic
  • The session remains IDLE
  • Selecting the defined id column succeeds

处置

Correct the column name or migration, then rerun the query against the intended relation.

清理

Drop the case schema with an owner connection.

报文

选定的 errorMissingColumn 分支以明确的 ERROR 发出主报文 column "%s" does not exist%s 是未解析列名,其他源码分支可能追加建议 HINT 或使用带关系限定的形式。只有客户端异常而没有服务器 SQLSTATE 和主报文时,不能据此认定 42703

报文模板

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

代表案例

本页使用与运行器注册表相同的语句。执行时,syntax_schemasyntax_role 等生成名称会替换为一次性实例中的实际值。

CREATE TABLE syntax_schema.column_table (id integer);
INSERT INTO syntax_schema.column_table VALUES (1);
SELECT missing_column FROM syntax_schema.column_table;
SELECT id FROM syntax_schema.column_table;

选定的 18.6 运行记录结构化诊断并通过修复断言;10.21 运行通过同一案例的具体检查。可下载的案例和证据投影分别是 42703 案例 JSON作者证据。运行器清单为 verify/cases/42703/cases.json,页面 SQL 会与共享注册表核对。

版本

选定的自然运行范围是 PostgreSQL 18.6 与 10.21,不能据此推断所有中间版本的行为。

来源

证据

断言

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

  • 42703 is the undefined_column condition in Class 42.

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

    不覆盖Directory identity does not identify every backend path.

    来源src/backend/utils/errcodes.txt

  • The fixed source calls for 42703 include the mechanism and message boundary selected for this page.

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

    不覆盖Other calls can use the same SQLSTATE with different context or dynamic fields.

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

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

    核实方式Run the shared registry case and inspect structured diagnostics, state/recovery assertions, and cleanup.

    不覆盖This covers the selected case and targets only; it does not generalize to all drivers or intermediate releases.

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

  • The locked catalogue records 42703; runtime scope is limited to the selected targets.

    核实方式Read generated facts and selected summaries.

    不覆盖Definition presence is not an exact behavioral introduction.

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

运行记录

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

同类错误代码

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