↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

42P16 — 无效表定义

表定义无效,如分区键或主键规则冲突。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

aliases
未知
class name
Syntax Error or Access Rule Violation
condition name
invalid_table_definition
lang
en
sqlstate
42P16

版本定义 PG 18

42P16 — 无效表定义

速览 {#at-a-glance}

42P16(invalid_table_definition)表定义可能违反分区键、排序规则或主键规则。

含义 {#meaning}

表定义检查在多种关系形状违规时使用此条件。18.6 核心示例拒绝分区键中的伪类型、支持排序规则的分区键缺少派生排序规则,以及同一表存在多个主键。

诊断 {#diagnosis}

根据完整消息确定表和列。检查分区键的 pg_attribute/pg_type,确认支持排序规则的类型是否有正确排序规则,并在修改 DDL 前列出现有主键约束。

处理 {#response}

只修改冲突的表定义:使用受支持的具体分区键类型,在源码要求时显式添加 COLLATE,或保留一个预期主键并从迁移中删除重复声明。如果 ERROR 发生在显式事务中,修正 DDL 前先 ROLLBACK 或回滚到错误前的保存点;不要继续向已中止的事务发送表变更。

消息 {#messages}

固定源码中的代表性消息包括: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。占位符由实际对象、列或参数填充。

版本 {#versions}

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

相关 {#related}

来源 {#sources}

源码消息、行号和证据边界见 作者证据。

比较版本

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.42P16.18.6"
  ],
  "statement": "42P16 is the invalid_table_definition condition in Class 42."
}
claims · mechanism.selected-source-path
{
  "claim_id": "mechanism.selected-source-path",
  "limits": "Representative confirmed core paths only; not exhaustive historical or extension coverage.",
  "method": "Read selected resolved REL_18_6 report groups and message roles.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.call.42P16.af3eab51674420e4a935dec6",
    "src.call.42P16.ba3688fe3791594da97fde08",
    "src.call.42P16.ca2b8fc15fc050d4a6cd2d3b"
  ],
  "statement": "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."
}
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.42P16.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": "partition key column %s has pseudo-type %s",
    "roles": [
      {
        "role": "errmsg",
        "template": "partition key column %s has pseudo-type %s"
      }
    ],
    "severity_source": "ERROR",
    "sources": [
      "src.call.42P16.af3eab51674420e4a935dec6"
    ],
    "sqlstate": "42P16"
  },
  "severity": "ERROR",
  "sources": [
    "src.call.42P16.af3eab51674420e4a935dec6"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "partition key column has pseudo-type",
      "position": 0,
      "role": "",
      "template": "partition key column %s has pseudo-type %s"
    }
  ]
}
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": [],
    "hint_templates": [
      "Use the COLLATE clause to set the collation explicitly."
    ],
    "id": "message.variant-2",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "no collation was derived for partition key column %s with collatable type %s",
    "roles": [
      {
        "role": "errmsg",
        "template": "no collation was derived for partition key column %s with collatable type %s"
      },
      {
        "role": "errhint",
        "template": "Use the COLLATE clause to set the collation explicitly."
      }
    ],
    "severity_source": "ERROR",
    "sources": [
      "src.call.42P16.ba3688fe3791594da97fde08"
    ],
    "sqlstate": "42P16"
  },
  "severity": "ERROR",
  "sources": [
    "src.call.42P16.ba3688fe3791594da97fde08"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "no collation was derived for partition key column with collatable type",
      "position": 0,
      "role": "",
      "template": "no collation was derived for partition key column %s with collatable type %s"
    },
    {
      "kind": "hint",
      "literal": "Use the COLLATE clause to set the collation explicitly.",
      "position": 1,
      "role": "",
      "template": "Use the COLLATE clause to set the collation explicitly."
    },
    {
      "kind": "primary",
      "literal": "Use the COLLATE clause to set the collation explicitly.",
      "position": 2,
      "role": "errhint",
      "template": "Use the COLLATE clause to set the collation explicitly."
    }
  ]
}
messages · message.variant-3
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-3",
  "path": "",
  "position": 2,
  "raw": {
    "detail_templates": [],
    "hint_templates": [],
    "id": "message.variant-3",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "multiple primary keys for table \"%s\" are not allowed",
    "roles": [
      {
        "role": "errmsg",
        "template": "multiple primary keys for table \"%s\" are not allowed"
      }
    ],
    "severity_source": "ERROR",
    "sources": [
      "src.call.42P16.ca2b8fc15fc050d4a6cd2d3b"
    ],
    "sqlstate": "42P16"
  },
  "severity": "ERROR",
  "sources": [
    "src.call.42P16.ca2b8fc15fc050d4a6cd2d3b"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "multiple primary keys for table \" \" are not allowed",
      "position": 0,
      "role": "",
      "template": "multiple primary keys for table \"%s\" are not allowed"
    }
  ]
}
sources · src.errcodes.42P16.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "line 397",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.42P16.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L397"
}
sources · src.call.42P16.af3eab51674420e4a935dec6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 576-580",
  "path": "src/backend/catalog/heap.c",
  "position": 1,
  "sha256": "e720ee58279590793edd0985b3c910970ef56e7361b8ef92e245370587e02a0e",
  "source_id": "src.call.42P16.af3eab51674420e4a935dec6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/heap.c#L576-L580"
}
sources · src.call.42P16.ba3688fe3791594da97fde08
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 697-702",
  "path": "src/backend/catalog/heap.c",
  "position": 2,
  "sha256": "e720ee58279590793edd0985b3c910970ef56e7361b8ef92e245370587e02a0e",
  "source_id": "src.call.42P16.ba3688fe3791594da97fde08",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/heap.c#L697-L702"
}
sources · src.call.42P16.ca2b8fc15fc050d4a6cd2d3b
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 218-221",
  "path": "src/backend/catalog/index.c",
  "position": 3,
  "sha256": "98a4156a5c21ae856a3b583b633cdeb578a5b69910386c9f166d69fcb04ba2d0",
  "source_id": "src.call.42P16.ca2b8fc15fc050d4a6cd2d3b",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/index.c#L218-L221"
}
sources · src.calls.REL_18_6.42P16
{
  "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.42P16",
  "tag": "",
  "url": ""
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:9d8289f1c339d7a9caed76425827824e5d48b1a1d61eeb48db0b6bf8ac535326

正文语言: zh-Hans · english-manuals:9d8289f1c339d7a9caed76425827824e5d48b1a1d61eeb48db0b6bf8ac535326