百科 / 错误代码 / Class 42 语法错误或访问规则冲突
42P16 invalid_table_definition
无效表定义
ERROR 源码确认 参考 未实测
- 条件名
invalid_table_definition- 宏名称
ERRCODE_INVALID_TABLE_DEFINITION- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
42P16(invalid_table_definition)表定义可能违反分区键、排序规则或主键规则。
含义
表定义检查在多种关系形状违规时使用此条件。18.6 核心示例拒绝分区键中的伪类型、支持排序规则的分区键缺少派生排序规则,以及同一表存在多个主键。
诊断
根据完整消息确定表和列。检查分区键的 pg_attribute/pg_type,确认支持排序规则的类型是否有正确排序规则,并在修改 DDL 前列出现有主键约束。
处理
只修改冲突的表定义:使用受支持的具体分区键类型,在源码要求时显式添加 COLLATE,或保留一个预期主键并从迁移中删除重复声明。如果 ERROR 发生在显式事务中,修正 DDL 前先 ROLLBACK 或回滚到错误前的保存点;不要继续向已中止的事务发送表变更。
消息
固定源码中的代表性消息包括:message: partition key column %s has pseudo-type %s;message: no collation was derived for partition key column %s with collatable type %s; HINT: Use the COLLATE clause to set the collation explicitly.;message: multiple primary keys for table "%s" are not allowed。占位符由实际对象、列或参数填充。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
partition key column %s has pseudo-type %s
来源:src/backend/catalog/heap.c(lines 576-580) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
no collation was derived for partition key column %s with collatable type %s
Use the COLLATE clause to set the collation explicitly.
Use the COLLATE clause to set the collation explicitly.
来源:src/backend/catalog/heap.c(lines 697-702) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
multiple primary keys for table "%s" are not allowed
来源:src/backend/catalog/index.c(lines 218-221) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
版本
锁定目录显示该条件最早见于 PostgreSQL 7.4;行为说明固定在 PostgreSQL 18.6 源码,目录存在范围不等于每条消息或功能都从该版本开始。
来源
- 上游源码 src/backend/catalog/heap.c 第 576–580 行
- 上游源码 src/backend/catalog/heap.c 第 697–702 行
- 上游源码 src/backend/catalog/index.c 第 218–221 行
- 上游源码 src/backend/utils/errcodes.txt 第 397 行
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
42P16 is the invalid_table_definition condition in Class 42.
-
Table-definition checks use this condition for several relation-shape violations. Core 18.6 examples reject pseudo-types in partition keys, missing collation for a collatable partition key, and multiple primary keys.
-
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_alias42P10invalid_column_reference42P11invalid_cursor_definition42P12invalid_database_definition42P13invalid_function_definition42P14invalid_prepared_statement_definition42P15invalid_schema_definition42P17invalid_object_definition42P18indeterminate_datatype42P19invalid_recursion42P20windowing_error42P21collation_mismatch42P22indeterminate_collation