百科 / 错误代码 / Class 42 语法错误或访问规则冲突
42P10 invalid_column_reference
无效列引用
ERROR 源码确认 参考 未实测
- 条件名
invalid_column_reference- 宏名称
ERRCODE_INVALID_COLUMN_REFERENCE- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
42P10(invalid_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
Generated columns cannot be used in COPY.
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 源码,目录存在范围不等于每条消息或功能都从该版本开始。
来源
- 上游源码 src/backend/catalog/heap.c 第 3465–3468 行
- 上游源码 src/backend/commands/copy.c 第 1026–1030 行
- 上游源码 src/backend/optimizer/util/plancat.c 第 958–960 行
- 上游源码 src/backend/utils/errcodes.txt 第 390 行
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
42P10 is the invalid_column_reference condition in Class 42.
-
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.
-
Locked catalogue snapshots show this condition by PostgreSQL 7.4; source behavior here is fixed at PostgreSQL 18.6.
同类错误代码
Class 42 语法错误或访问规则冲突 下的其他成员。
42000syntax_error_or_access_rule_violation42501insufficient_privilege42601syntax_error42602invalid_name42611invalid_column_definition42622name_too_long42701duplicate_column42702ambiguous_column42703undefined_column42704undefined_object42710duplicate_object42712duplicate_alias42723duplicate_function42725ambiguous_function42803grouping_error42804datatype_mismatch42809wrong_object_type42830invalid_foreign_key42846cannot_coerce42883undefined_function428C9generated_always42939reserved_name42P01undefined_table42P02undefined_parameter42P03duplicate_cursor42P04duplicate_database42P05duplicate_prepared_statement42P06duplicate_schema42P07duplicate_table42P08ambiguous_parameter42P09ambiguous_alias42P11invalid_cursor_definition42P12invalid_database_definition42P13invalid_function_definition42P14invalid_prepared_statement_definition42P15invalid_schema_definition42P16invalid_table_definition42P17invalid_object_definition42P18indeterminate_datatype42P19invalid_recursion42P20windowing_error42P21collation_mismatch42P22indeterminate_collation