百科 / 错误代码 / Class 42 语法错误或访问规则冲突
42611 invalid_column_definition
列定义无效
ERROR 已实测 参考 实测通过
- 条件名
invalid_column_definition- 宏名称
ERRCODE_INVALID_COLUMN_DEFINITION- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
SQLSTATE 42611 是 Class 42 中的 invalid_column_definition。42611 表示列定义无效。选定案例中的两个继承父表为 id 定义了不同默认值;子表 DDL 失败并报告 column "%s" inherits conflicting default values,提示显式指定默认值。
含义
42611 表示列定义无效。在 MergeAttributes 中,PostgreSQL 按父表顺序合并同名列。如果继承来的默认表达式不相等,且子表没有覆盖它,最终检查会发出 ERROR:column "%s" inherits conflicting default values,并提示显式指定默认值。选定案例的两个父表为 id 定义了不同默认值。
诊断
检查 INHERITS 列表中的每个父表,比较同名列的类型、排序规则、可空性和默认表达式。相同默认值可以合并;子表本地默认值可以覆盖继承冲突。选定 DDL 的 ERROR 后自动提交会话仍为 IDLE;这是继承默认值分支,不是一般的重复列错误,也不是类型/排序规则冲突。
处理
按服务器提示在子表定义中显式声明预期默认值,然后插入 DEFAULT VALUES 并核对结果。如果父表本应一致,应直接修复父表迁移;如果差异是有意的,就把子表覆盖值明确写在 DDL 中。选定修复返回 1,但这是案例值,不代表所有场景都应选择同一策略。
可复现案例
在一次性实例上执行过的场景。其中 1 个附有可执行 SQL,正文相应小节里给出。
conflicting_inherited_default PG 10 / 18 有 SQL
前置条件
- A runner-owned disposable target is provisioned.
触发
Create two parent tables with different defaults and inherit both without an explicit child default.
断言
- SQLSTATE is 42611 with the conflicting-default diagnostic
- The session remains IDLE
- An explicit child default resolves the inheritance conflict and DEFAULT inserts 1
处置
Specify the intended default explicitly on the child definition, then verify the inherited table.
清理
Drop the case schema with an owner connection.
报文
选定源码分支以明确的 ERROR 发出主报文 column "%s" inherits conflicting default values 和 HINT To resolve the conflict, specify a default explicitly. %s 是冲突列名。只有客户端异常而没有服务器 SQLSTATE、主报文和 HINT 时,不能据此识别这个选定的继承默认值子路径;其他固定 producer 可以使用同一 SQLSTATE 和不同诊断。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
column "%s" inherits conflicting default values
To resolve the conflict, specify a default explicitly.
来源:src/backend/commands/tablecmds.c @ REL_18_6 · src/backend/commands/tablecmds.c @ REL_10_23
代表案例
本页使用与运行器注册表相同的语句。执行时,syntax_schema、syntax_role 等生成名称会替换为一次性实例中的实际值。
CREATE TABLE syntax_schema.parent_one (id integer DEFAULT 1);
CREATE TABLE syntax_schema.parent_two (id integer DEFAULT 2);
CREATE TABLE syntax_schema.child_bad () INHERITS (syntax_schema.parent_one, syntax_schema.parent_two);
CREATE TABLE syntax_schema.child_good (id integer DEFAULT 1) INHERITS (syntax_schema.parent_one, syntax_schema.parent_two);
INSERT INTO syntax_schema.child_good DEFAULT VALUES RETURNING id;
选定的 18.6 运行记录结构化诊断并通过修复断言;10.21 运行通过同一案例的具体检查。可下载的案例和证据投影分别是 42611 案例 JSON 和 作者证据。运行器清单为 verify/cases/42611/cases.json,页面 SQL 会与共享注册表核对。
版本
选定的自然运行范围是 PostgreSQL 18.6 与 10.21,不能据此推断所有中间版本的行为。
来源
- 上游源码 src/backend/utils/errcodes.txt
- 上游源码 src/backend/commands/tablecmds.c 第 2288–2292 行
- 上游源码 src/backend/commands/tablecmds.c 第 3144–3148 行
- 核验材料 verify/cases/42611/cases.json
- 核验材料 verify/cases/42611/snippets.json
- 核验材料 raw/calls/REL_10_23.jsonl
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
42611 is the invalid_column_definition condition in Class 42.
-
The fixed source calls for 42611 include the mechanism and message boundary selected for this page.
-
The selected conflicting_inherited_default case passed on isolated PostgreSQL 18.6 and 10.21 targets.
-
The locked catalogue records 42611; runtime scope is limited to the selected targets.
运行记录
| 目标 | 服务器版本 | 结果 | 覆盖案例 |
|---|---|---|---|
| latest | 18.6 (Homebrew) | passed | |
| pg10 | 10.21 (Debian 10.21-1.pgdg90+1) | passed |
同类错误代码
Class 42 语法错误或访问规则冲突 下的其他成员。
42000syntax_error_or_access_rule_violation42501insufficient_privilege42601syntax_error42602invalid_name42622name_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_alias42P10invalid_column_reference42P11invalid_cursor_definition42P12invalid_database_definition42P13invalid_function_definition42P14invalid_prepared_statement_definition42P15invalid_schema_definition42P16invalid_table_definition42P17invalid_object_definition42P18indeterminate_datatype42P19invalid_recursion42P20windowing_error42P21collation_mismatch42P22indeterminate_collation