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

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

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

42P10 invalid_column_reference

无效列引用

ERROR 源码确认 参考 未实测

条件名
invalid_column_reference
宏名称
ERRCODE_INVALID_COLUMN_REFERENCE
启用版本
7.4
状态
活跃

版本覆盖

速览

42P10invalid_column_reference)使用列引用的具体操作可能拒绝该引用。

含义

多个消费者会因不同的列引用契约报告 42P10。18.6 选定路径中,cookConstraint 只允许引用拥有 CHECK 约束的表,CopyGetAttnums 拒绝在显式 COPY 列表中指定生成列(默认列表会跳过生成列),ON CONFLICT 仲裁器推断找不到合适索引时也会报告此码。后一种情况是推断失败,不是笼统的缺列错误。

诊断

先结合完整主消息和 DETAIL 判断阶段:CHECK 约束归属、显式 COPY 列表,还是 ON CONFLICT 仲裁器推断。COPY 要区分用户列列表和默认列表;ON CONFLICT 要按 action 检查候选索引的列或表达式、谓词、排序规则和操作符类;DO UPDATE 需要匹配的唯一仲裁器,排除约束不是该 action 的通用替代。没有阶段特定的报文时,不要先判定为缺列。

处理

修复具体契约:把 CHECK 放在所属表上,显式 COPY 列表排除生成列,或让 ON CONFLICT 与现有合适的唯一索引/约束及其推断细节一致。DO NOTHING 也要先核对该 action 的仲裁规则,再考虑排除约束。不要把创建任意约束当成通用修复。如果该 ERROR 发生在显式事务中,下一条命令前执行 ROLLBACK,或回滚到语句前建立的保存点,检查目录后再重试。

消息

固定源码中的代表性消息包括:message: only table "%s" can be referenced in check constraint;message: column "%s" is a generated column; DETAIL: Generated columns cannot be used in COPY.;message: there is no unique or exclusion constraint matching the ON CONFLICT specification。占位符由实际对象、列或参数填充。

报文模板

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

主消息 only table "%s" can be referenced in check constraint

来源:src/backend/catalog/heap.c(lines 3465-3468) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 column "%s" is a generated column
DETAIL Generated columns cannot be used in COPY.
主消息 · errdetail Generated columns cannot be used in COPY.

来源:src/backend/commands/copy.c(lines 1026-1030) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 there is no unique or exclusion constraint matching the ON CONFLICT specification

来源:src/backend/optimizer/util/plancat.c(lines 958-960) @ REL_18_6

适用范围:The primary is source-exact; DO UPDATE needs a matching unique arbiter, while an exclusion constraint is not a general substitute for that action. No concrete runtime value is claimed.

版本

锁定目录显示该条件最早见于 PostgreSQL 7.4;行为说明固定在 PostgreSQL 18.6 源码,目录存在范围不等于每条消息或功能都从该版本开始。

来源

证据

断言

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

  • 42P10 is the invalid_column_reference condition in Class 42.

    核实方式Read fixed REL_18_6 errcodes.txt and locked facts.

    不覆盖Identity does not enumerate all source branches or client failures.

    来源src/backend/utils/errcodes.txt(line 390)

  • Selected 18.6 paths use 42P10 for different column-reference contracts: cookConstraint permits only the table owning a CHECK constraint, CopyGetAttnums rejects a generated column named in an explicit COPY list while the default list skips generated columns, and ON CONFLICT inference reports this code when no suitable arbiter index matches. The ON CONFLICT message is an inference failure, not a generic missing-column error.

    核实方式Read selected resolved REL_18_6 report groups and message roles.

    不覆盖Representative confirmed core paths only; ON CONFLICT action-specific arbiter rules and historical/extension coverage are not exhaustive.

    来源src/backend/catalog/heap.c(lines 3465-3468) · src/backend/commands/copy.c(lines 1026-1030) · src/backend/optimizer/util/plancat.c(lines 958-960)

  • Locked catalogue snapshots show this condition by PostgreSQL 7.4; source behavior here is fixed at PostgreSQL 18.6.

    核实方式Read locked catalogue facts and definition snapshot.

    不覆盖First observed release is a lower bound, not precise behavioral introduction.

    来源src/backend/utils/errcodes.txt(line 390)

同类错误代码

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