42P10 — 无效列引用
列引用不符合该操作的契约,如 COPY 生成列。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Syntax Error or Access Rule Violation
- condition name
- invalid_column_reference
- lang
- en
- sqlstate
- 42P10
版本定义 PG 18
42P10 — 无效列引用
速览 {#at-a-glance}
42P10(invalid_column_reference)使用列引用的具体操作可能拒绝该引用。
含义 {#meaning}
多个消费者会因不同的列引用契约报告 42P10。18.6 选定路径中,cookConstraint 只允许引用拥有 CHECK 约束的表,CopyGetAttnums 拒绝在显式 COPY 列表中指定生成列(默认列表会跳过生成列),ON CONFLICT 仲裁器推断找不到合适索引时也会报告此码。后一种情况是推断失败,不是笼统的缺列错误。
诊断 {#diagnosis}
先结合完整主消息和 DETAIL 判断阶段:CHECK 约束归属、显式 COPY 列表,还是 ON CONFLICT 仲裁器推断。COPY 要区分用户列列表和默认列表;ON CONFLICT 要按 action 检查候选索引的列或表达式、谓词、排序规则和操作符类;DO UPDATE 需要匹配的唯一仲裁器,排除约束不是该 action 的通用替代。没有阶段特定的报文时,不要先判定为缺列。
处理 {#response}
修复具体契约:把 CHECK 放在所属表上,显式 COPY 列表排除生成列,或让 ON CONFLICT 与现有合适的唯一索引/约束及其推断细节一致。DO NOTHING 也要先核对该 action 的仲裁规则,再考虑排除约束。不要把创建任意约束当成通用修复。如果该 ERROR 发生在显式事务中,下一条命令前执行 ROLLBACK,或回滚到语句前建立的保存点,检查目录后再重试。
消息 {#messages}
固定源码中的代表性消息包括: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。占位符由实际对象、列或参数填充。
版本 {#versions}
锁定目录显示该条件最早见于 PostgreSQL 7.4;行为说明固定在 PostgreSQL 18.6 源码,目录存在范围不等于每条消息或功能都从该版本开始。
相关 {#related}
来源 {#sources}
源码消息、行号和证据边界见 作者证据。
src/backend/catalog/heap.c:3465-3468(fixed source)src/backend/commands/copy.c:1026-1030(fixed source)src/backend/optimizer/util/plancat.c:958-960(fixed source)
比较版本
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.42P10.18.6"
],
"statement": "42P10 is the invalid_column_reference condition in Class 42."
}claims · mechanism.selected-source-path
{
"claim_id": "mechanism.selected-source-path",
"limits": "Representative confirmed core paths only; ON CONFLICT action-specific arbiter rules and historical/extension coverage are not exhaustive.",
"method": "Read selected resolved REL_18_6 report groups and message roles.",
"position": 1,
"runtime": [],
"sources": [
"src.call.42P10.2fe5eef548819ba1cf9ab7c2",
"src.call.42P10.4cc3c771f6b98871572af1b5",
"src.call.42P10.9fb7b007472c34d677de2888"
],
"statement": "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."
}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 snapshot.",
"position": 2,
"runtime": [],
"sources": [
"src.errcodes.42P10.18.6"
],
"statement": "Locked catalogue snapshots show this condition by PostgreSQL 7.4; source behavior here is fixed at PostgreSQL 18.6."
}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": "only table \"%s\" can be referenced in check constraint",
"roles": [
{
"role": "errmsg",
"template": "only table \"%s\" can be referenced in check constraint"
}
],
"severity_source": "ERROR",
"sources": [
"src.call.42P10.2fe5eef548819ba1cf9ab7c2"
],
"sqlstate": "42P10"
},
"severity": "ERROR",
"sources": [
"src.call.42P10.2fe5eef548819ba1cf9ab7c2"
],
"templates": [
{
"kind": "primary",
"literal": "only table \" \" can be referenced in check constraint",
"position": 0,
"role": "",
"template": "only table \"%s\" can be referenced in check constraint"
}
]
}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": [
"Generated columns cannot be used in COPY."
],
"hint_templates": [],
"id": "message.variant-2",
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"primary_template": "column \"%s\" is a generated column",
"roles": [
{
"role": "errmsg",
"template": "column \"%s\" is a generated column"
},
{
"role": "errdetail",
"template": "Generated columns cannot be used in COPY."
}
],
"severity_source": "ERROR",
"sources": [
"src.call.42P10.4cc3c771f6b98871572af1b5"
],
"sqlstate": "42P10"
},
"severity": "ERROR",
"sources": [
"src.call.42P10.4cc3c771f6b98871572af1b5"
],
"templates": [
{
"kind": "primary",
"literal": "column \" \" is a generated column",
"position": 0,
"role": "",
"template": "column \"%s\" is a generated column"
},
{
"kind": "detail",
"literal": "Generated columns cannot be used in COPY.",
"position": 1,
"role": "",
"template": "Generated columns cannot be used in COPY."
},
{
"kind": "primary",
"literal": "Generated columns cannot be used in COPY.",
"position": 2,
"role": "errdetail",
"template": "Generated columns cannot be used in COPY."
}
]
}messages · message.variant-3
{
"limits": "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.",
"message_id": "message.variant-3",
"path": "",
"position": 2,
"raw": {
"detail_templates": [],
"hint_templates": [],
"id": "message.variant-3",
"limits": "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.",
"primary_template": "there is no unique or exclusion constraint matching the ON CONFLICT specification",
"roles": [
{
"role": "errmsg",
"template": "there is no unique or exclusion constraint matching the ON CONFLICT specification"
}
],
"severity_source": "ERROR",
"sources": [
"src.call.42P10.9fb7b007472c34d677de2888"
],
"sqlstate": "42P10"
},
"severity": "ERROR",
"sources": [
"src.call.42P10.9fb7b007472c34d677de2888"
],
"templates": [
{
"kind": "primary",
"literal": "there is no unique or exclusion constraint matching the ON CONFLICT specification",
"position": 0,
"role": "",
"template": "there is no unique or exclusion constraint matching the ON CONFLICT specification"
}
]
}sources · src.errcodes.42P10.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "line 390",
"path": "src/backend/utils/errcodes.txt",
"position": 0,
"sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
"source_id": "src.errcodes.42P10.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L390"
}sources · src.call.42P10.2fe5eef548819ba1cf9ab7c2
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "lines 3465-3468",
"path": "src/backend/catalog/heap.c",
"position": 1,
"sha256": "e720ee58279590793edd0985b3c910970ef56e7361b8ef92e245370587e02a0e",
"source_id": "src.call.42P10.2fe5eef548819ba1cf9ab7c2",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/heap.c#L3465-L3468"
}sources · src.call.42P10.4cc3c771f6b98871572af1b5
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "lines 1026-1030",
"path": "src/backend/commands/copy.c",
"position": 2,
"sha256": "f50ecc1531109fc172d841d461e209cef611f3d017ef4184034c39e128deabbe",
"source_id": "src.call.42P10.4cc3c771f6b98871572af1b5",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/copy.c#L1026-L1030"
}sources · src.call.42P10.9fb7b007472c34d677de2888
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "lines 958-960",
"path": "src/backend/optimizer/util/plancat.c",
"position": 3,
"sha256": "b953af14cb2539fbb32e4d1e8eea30f3eaa1b6336091369c03531fb9dcd5a6ff",
"source_id": "src.call.42P10.9fb7b007472c34d677de2888",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/optimizer/util/plancat.c#L958-L960"
}sources · src.calls.REL_18_6.42P10
{
"commit": "",
"docs_url": "",
"kind": "local_artifact",
"location": "",
"path": "raw/calls/REL_18_6.jsonl",
"position": 4,
"sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
"source_id": "src.calls.REL_18_6.42P10",
"tag": "",
"url": ""
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:ba6f1dd1a717b31f4f226abff0efa3e520b9e45966d5b266e946609534727bf4
正文语言: zh-Hans · english-manuals:ba6f1dd1a717b31f4f226abff0efa3e520b9e45966d5b266e946609534727bf4