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

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

Wiki / SQLSTATE

22030 — duplicate_json_object_key_value

构造 JSON 对象时出现重复键。

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

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

aliases
未知
class name
Data Exception
condition name
duplicate_json_object_key_value
lang
en
sqlstate
22030

版本定义 PG 18

22030

速览 {#at-a-glance}

构造 JSON 对象时遇到重复键。固定的 JSON 唯一键构造器和聚合路径报告 duplicate JSON object key value: %s;JSONB 对象收尾有相关变体。

报文 {#messages}

唯一键路径使用以下首要文本:

| 路径 | 首要文本 | | --- | --- | | 启用唯一键的 JSON 构造器或聚合 | duplicate JSON object key value: %s | | JSONB 对象收尾或唯一键校验 | duplicate JSON object key value |

含义 {#meaning}

当 JSON 对象操作明确启用键唯一性,并在同一对象中再次遇到同名键时,会报告 22030。JSON 构造器和对象聚合携带 unique_keys 标志;唯一键变体记录已见键,并在插入或对象收尾时报告错误。普通 json/jsonb 输入将该标志设为 false,普通构造器或聚合也不会把输入文本中的每个重复键都变成 22030。strict 或 absent-on-null 变体会从输出中省略 NULL 值,但唯一键变体仍会保留键并检查唯一性,因此即使值将被跳过,重复键仍可能失败。对象键本身为 NULL 属于独立的参数错误。

诊断 {#diagnosis}

确认构造器或聚合,以及其文档规定的形式是否强制唯一键。JSON 构造器/聚合路径的 %s 报文会给出重复键;JSONB 收尾和校验路径使用较短的首要文本。区分重复键策略、无效 JSON 语法、NULL 对象键,以及按普通语义允许重复输入的 json/jsonb 解析。

处理 {#response}

按所属实现的重复键策略处理:需要唯一性时在上游去重或汇总;只有在确实要保留重复键语义时,才使用文档规定的非唯一操作。不要通过修改唯一键标志来解决 NULL 键或格式错误的 JSON。如果 ERROR 发生在显式事务中,应先 ROLLBACK 或回滚到既有保存点再重试;自动提交可重试修正后的动作。

版本 {#versions}

锁定目录从 12.0 起记录该条件;本页固定 JSON 和 JSONB 源码路径为 PostgreSQL 18.6。未声称本页有自然运行观察。

相关 {#related}

22032、22023

来源 {#sources}

JSON 唯一键构造器和聚合见 src/backend/utils/adt/json.c#L1002-1127 和 #L1224-1295;JSON 唯一性校验见 #L1810-1853。JSONB 普通输入在 src/backend/utils/adt/jsonb.c#L74-102 中关闭唯一性;唯一键构造和对象收尾见 #L1125-1163 与 src/backend/utils/adt/jsonb_util.c#L1952-2005。结构化证据记录保留唯一键和 NULL 跳过边界;本页未运行自然案例。

比较版本

SQLSTATE 证据与已记录的运行版本

claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read fixed definition.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "22030 is duplicate_json_object_key_value in SQLSTATE Class 22."
}
claims · resolved-path
{
  "claim_id": "resolved-path",
  "limits": "Source confirmation is not a natural runtime observation.",
  "method": "Read the complete unique-key builder, parser-validation, JSONB input, and final uniqueify paths.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.path.0",
    "src.json.unique-builder",
    "src.json.unique-constructor",
    "src.json.unique-validate",
    "src.jsonb.unique-builder",
    "src.jsonb.input",
    "src.jsonb.uniqueify"
  ],
  "statement": "Fixed JSON and JSONB builders/aggregates enable uniqueness checks only for their unique-key variants; duplicate keys then raise 22030, while ordinary json/jsonb input leaves unique_keys false and does not use this guard. Strict/absent-on-null variants skip NULL-valued entries from output but retain their key long enough to enforce uniqueness when unique_keys is true."
}
claims · history
{
  "claim_id": "history",
  "limits": "",
  "method": "Use catalogue boundary.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "The locked catalogue records 22030 from 12.0 without proving exact implementation introduction."
}
messages · message.0
{
  "limits": "",
  "message_id": "message.0",
  "path": "",
  "position": 0,
  "raw": {
    "id": "message.0",
    "primary_template": "duplicate JSON object key value: %s",
    "severity_source": "ERROR",
    "sources": [
      "src.path.0"
    ],
    "sqlstate": "22030"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.0"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "duplicate JSON object key value:",
      "position": 0,
      "role": "",
      "template": "duplicate JSON object key value: %s"
    }
  ]
}
messages · message.jsonb
{
  "limits": "",
  "message_id": "message.jsonb",
  "path": "",
  "position": 1,
  "raw": {
    "id": "message.jsonb",
    "primary_template": "duplicate JSON object key value",
    "severity_source": "ERROR",
    "sources": [
      "src.jsonb.uniqueify"
    ],
    "sqlstate": "22030"
  },
  "severity": "ERROR",
  "sources": [
    "src.jsonb.uniqueify"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "duplicate JSON object key value",
      "position": 0,
      "role": "",
      "template": "duplicate JSON object key value"
    }
  ]
}
messages · message.json-validate
{
  "limits": "",
  "message_id": "message.json-validate",
  "path": "",
  "position": 2,
  "raw": {
    "id": "message.json-validate",
    "primary_template": "duplicate JSON object key value",
    "severity_source": "ERROR",
    "sources": [
      "src.json.unique-validate"
    ],
    "sqlstate": "22030"
  },
  "severity": "ERROR",
  "sources": [
    "src.json.unique-validate"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "duplicate JSON object key value",
      "position": 0,
      "role": "",
      "template": "duplicate JSON object key value"
    }
  ]
}
sources · src.errcodes.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L215"
}
sources · src.path.0
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/json.c",
  "position": 1,
  "sha256": "9d0ed0ee9d5bac07990f2b413b48ba7dac2bff3b24797233fd887926a704c102",
  "source_id": "src.path.0",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/json.c#L1124"
}
sources · src.json.unique-builder
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/json.c",
  "position": 2,
  "sha256": "9d0ed0ee9d5bac07990f2b413b48ba7dac2bff3b24797233fd887926a704c102",
  "source_id": "src.json.unique-builder",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/json.c#L1002"
}
sources · src.json.unique-constructor
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/json.c",
  "position": 3,
  "sha256": "9d0ed0ee9d5bac07990f2b413b48ba7dac2bff3b24797233fd887926a704c102",
  "source_id": "src.json.unique-constructor",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/json.c#L1224"
}
sources · src.json.unique-validate
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/json.c",
  "position": 4,
  "sha256": "9d0ed0ee9d5bac07990f2b413b48ba7dac2bff3b24797233fd887926a704c102",
  "source_id": "src.json.unique-validate",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/json.c#L1810"
}
sources · src.jsonb.unique-builder
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/jsonb.c",
  "position": 5,
  "sha256": "b137e223a73a8a4287e9b3a4d7dedcb3a3a40bdd9d08c6e5c5fd998d4139ba3f",
  "source_id": "src.jsonb.unique-builder",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/jsonb.c#L1125"
}
sources · src.jsonb.input
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/jsonb.c",
  "position": 6,
  "sha256": "b137e223a73a8a4287e9b3a4d7dedcb3a3a40bdd9d08c6e5c5fd998d4139ba3f",
  "source_id": "src.jsonb.input",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/jsonb.c#L74"
}
sources · src.jsonb.uniqueify
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/jsonb_util.c",
  "position": 7,
  "sha256": "444230d5187605ae276d3197fab41033e530e2dcbd94721d900005c7a52eb7b0",
  "source_id": "src.jsonb.uniqueify",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/jsonb_util.c#L1952"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:78c0cba9e069ad8f0f295af9d5b5e0f34b26e97ed6847d6ad96b43a148c7d75b

正文语言: zh-Hans · english-manuals:78c0cba9e069ad8f0f295af9d5b5e0f34b26e97ed6847d6ad96b43a148c7d75b