↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / SQLSTATE

22026 — string_data_length_mismatch

A bit-string value has the wrong declared length. The fixed varbit.c path reports bit string length %d does not match type bit(%d); bitwise operands have separate mismatch messages.

English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

aliases
Unknown
class name
Data Exception
condition name
string_data_length_mismatch
lang
en
sqlstate
22026

Definition PG 18

22026

At a glance {#at-a-glance}

A bit-string value has the wrong declared length. The fixed varbit.c path reports bit string length %d does not match type bit(%d); bitwise operands have separate mismatch messages.

Messages {#messages}

The fixed guards use these primary texts:

| Guard | Primary | | --- | --- | | bit(n) length mismatch | bit string length %d does not match type bit(%d) | | bit_and operands | cannot AND bit strings of different sizes | | bit_or operands | cannot OR bit strings of different sizes | | bitxor operands | cannot XOR bit strings of different sizes |

Meaning {#meaning}

22026 covers exact-length bit(n) boundaries and bitwise operations. The fixed bit() input path compares the actual bit length with the declared bit(n) length; an implicit conversion raises bit string length %d does not match type bit(%d), while an explicit bit(n) cast truncates or zero-pads. The varbit(n) path has a different contract: an implicit value that is too long uses 22001, and an explicit cast truncates to the maximum length. The AND, OR, and XOR functions separately compare both operand lengths and use 22026 when they differ.

Diagnosis {#diagnosis}

First identify whether the primary names a bit(n) typmod or a bitwise operator. For the typmod message, compare the source bit length with the target exact length and check whether the boundary is an implicit assignment/cast or an explicitly requested cast. For varbit(n) overlength, look for 22001 instead; for a bitwise message, inspect both operands. Character width and encoding failures belong to different SQLSTATE paths.

Response {#response}

Make an implicit bit(n) value exactly the declared length. Use an explicit cast only when its truncation or zero-padding is intended, and resize both operands before a bitwise operation when their lengths should agree. If an ERROR occurred in an explicit transaction, roll back or roll back to the existing savepoint before retrying; autocommit can retry the corrected action.

Versions {#versions}

The locked catalogue records this condition from 7.4; the fixed source paths here are PostgreSQL 18.6. No natural runtime observation is claimed for this page.

Related {#related}

22001, 22021

Sources {#sources}

The exact-length guard is src/backend/utils/adt/varbit.c#L354-357; implicit versus explicit bit(n) and varbit(n) conversion is #L385-414 and #L736-765. The bitwise size guards are #L1257-1343. The structured evidence record retains the message roles and scope; no natural runtime was run.

Compare versions

SQLSTATE evidence and recorded runtime versions

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"
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:5f5eef27d574995206d53273d8ff2b22dcb6e2ee97dfbd9b127c8a64c59df4c1

Text language: en · english-manuals:5f5eef27d574995206d53273d8ff2b22dcb6e2ee97dfbd9b127c8a64c59df4c1