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

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

Wiki / SQLSTATE

22026 — string_data_length_mismatch

位串长度与声明的类型长度不一致。

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

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

aliases
未知
class name
Data Exception
condition name
string_data_length_mismatch
lang
en
sqlstate
22026

版本定义 PG 18

22026

速览 {#at-a-glance}

位串值与声明长度不匹配。固定 varbit.c 路径报告 bit string length %d does not match type bit(%d);位运算操作数有单独的长度不匹配报文。

报文 {#messages}

固定守卫使用以下首要文本:

| 守卫 | 首要文本 | | --- | --- | | bit(n) 长度不匹配 | bit string length %d does not match type bit(%d) | | bit_and 操作数 | cannot AND bit strings of different sizes | | bit_or 操作数 | cannot OR bit strings of different sizes | | bitxor 操作数 | cannot XOR bit strings of different sizes |

含义 {#meaning}

22026 覆盖精确长度的 bit(n) 边界和位运算。固定 bit() 输入路径将实际位长与声明的 bit(n) 长度比较;隐式转换会报告 bit string length %d does not match type bit(%d),显式 bit(n) 转换则会截断或补零。varbit(n) 使用不同约束:隐式值过长时使用 22001,显式转换会截断到最大长度。AND、OR 和 XOR 函数另行比较两个操作数的长度,长度不同时使用 22026。

诊断 {#diagnosis}

先判断首要报文指出的是 bit(n) typmod 还是位运算符。对于 typmod 报文,比较源位长和目标精确长度,并确认边界是隐式赋值/转换还是明确要求的显式转换。varbit(n) 过长应寻找 22001;位运算报文则检查两个操作数。字符宽度和编码失败属于其他 SQLSTATE 路径。

处理 {#response}

使隐式 bit(n) 值恰好达到声明长度。只有在确实需要截断或补零时才使用显式转换;位运算需要同长时,先调整两个操作数。如果 ERROR 发生在显式事务中,应先 ROLLBACK 或回滚到既有保存点再重试;自动提交可重试修正后的动作。

版本 {#versions}

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

相关 {#related}

22001、22021

来源 {#sources}

精确长度守卫在 src/backend/utils/adt/varbit.c#L354-357;bit(n) 与 varbit(n) 的隐式/显式转换见 #L385-414 和 #L736-765。位运算尺寸守卫见 #L1257-1343。结构化证据记录保留报文角色与范围;本页未运行自然案例。

比较版本

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

claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read fixed definition.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "22026 is string_data_length_mismatch in SQLSTATE Class 22."
}
claims · resolved-path
{
  "claim_id": "resolved-path",
  "limits": "Source confirmation is not a natural runtime observation.",
  "method": "Read the complete bit/varbit cast and bitwise guard contexts.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.path.0",
    "src.varbit.bit-cast",
    "src.varbit.varbit-cast",
    "src.varbit.bitops"
  ],
  "statement": "The fixed varbit source separates exact bit typmod assignment from explicit bit(n) casts, and uses 22026 for unequal bitwise operand lengths; explicit bit(n) casts truncate or zero-pad, while implicit varbit(n) overlength uses 22001."
}
claims · history
{
  "claim_id": "history",
  "limits": "",
  "method": "Use catalogue boundary.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "The locked catalogue records 22026 from 7.4 without proving exact implementation introduction."
}
messages · message.0
{
  "limits": "",
  "message_id": "message.0",
  "path": "",
  "position": 0,
  "raw": {
    "id": "message.0",
    "primary_template": "bit string length %d does not match type bit(%d)",
    "severity_source": "ERROR",
    "sources": [
      "src.path.0"
    ],
    "sqlstate": "22026"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.0"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "bit string length does not match type bit( )",
      "position": 0,
      "role": "",
      "template": "bit string length %d does not match type bit(%d)"
    }
  ]
}
messages · message.bit-and
{
  "limits": "",
  "message_id": "message.bit-and",
  "path": "",
  "position": 1,
  "raw": {
    "id": "message.bit-and",
    "primary_template": "cannot AND bit strings of different sizes",
    "severity_source": "ERROR",
    "sources": [
      "src.varbit.bitops"
    ],
    "sqlstate": "22026"
  },
  "severity": "ERROR",
  "sources": [
    "src.varbit.bitops"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "cannot AND bit strings of different sizes",
      "position": 0,
      "role": "",
      "template": "cannot AND bit strings of different sizes"
    }
  ]
}
messages · message.bit-or
{
  "limits": "",
  "message_id": "message.bit-or",
  "path": "",
  "position": 2,
  "raw": {
    "id": "message.bit-or",
    "primary_template": "cannot OR bit strings of different sizes",
    "severity_source": "ERROR",
    "sources": [
      "src.varbit.bitops"
    ],
    "sqlstate": "22026"
  },
  "severity": "ERROR",
  "sources": [
    "src.varbit.bitops"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "cannot OR bit strings of different sizes",
      "position": 0,
      "role": "",
      "template": "cannot OR bit strings of different sizes"
    }
  ]
}
messages · message.bit-xor
{
  "limits": "",
  "message_id": "message.bit-xor",
  "path": "",
  "position": 3,
  "raw": {
    "id": "message.bit-xor",
    "primary_template": "cannot XOR bit strings of different sizes",
    "severity_source": "ERROR",
    "sources": [
      "src.varbit.bitops"
    ],
    "sqlstate": "22026"
  },
  "severity": "ERROR",
  "sources": [
    "src.varbit.bitops"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "cannot XOR bit strings of different sizes",
      "position": 0,
      "role": "",
      "template": "cannot XOR bit strings of different sizes"
    }
  ]
}
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#L199"
}
sources · src.path.0
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/varbit.c",
  "position": 1,
  "sha256": "f719afe56683db3714a41d2f49f454a6b65b38e310c00d5afe47cbc44fd9480d",
  "source_id": "src.path.0",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/varbit.c#L354"
}
sources · src.varbit.bit-cast
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/varbit.c",
  "position": 2,
  "sha256": "f719afe56683db3714a41d2f49f454a6b65b38e310c00d5afe47cbc44fd9480d",
  "source_id": "src.varbit.bit-cast",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/varbit.c#L385"
}
sources · src.varbit.varbit-cast
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/varbit.c",
  "position": 3,
  "sha256": "f719afe56683db3714a41d2f49f454a6b65b38e310c00d5afe47cbc44fd9480d",
  "source_id": "src.varbit.varbit-cast",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/varbit.c#L736"
}
sources · src.varbit.bitops
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/varbit.c",
  "position": 4,
  "sha256": "f719afe56683db3714a41d2f49f454a6b65b38e310c00d5afe47cbc44fd9480d",
  "source_id": "src.varbit.bitops",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/varbit.c#L1257"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:5f5eef27d574995206d53273d8ff2b22dcb6e2ee97dfbd9b127c8a64c59df4c1

正文语言: zh-Hans · english-manuals:5f5eef27d574995206d53273d8ff2b22dcb6e2ee97dfbd9b127c8a64c59df4c1