22026
Read PG 18 manual ↗string_data_length_mismatch
- SQLSTATE
- 22026
- Condition name
- string_data_length_mismatch
- Class
- Data Exception
- Source macro
- ERRCODE_STRING_DATA_LENGTH_MISMATCH
- Evidence
- Source path confirmed
English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗
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
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
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
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
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
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.
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.
Source evidence
Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.
22026 is string_data_length_mismatch in SQLSTATE Class 22.
Method: Read fixed definition.
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.
Method: Read the complete bit/varbit cast and bitwise guard contexts.
Limits: Source confirmation is not a natural runtime observation.
src.path.0 src.varbit.bit-cast src.varbit.varbit-cast src.varbit.bitops
The locked catalogue records 22026 from 7.4 without proving exact implementation introduction.
Method: Use catalogue boundary.
- src/backend/utils/errcodes.txt · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/utils/adt/varbit.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/utils/adt/varbit.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/utils/adt/varbit.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/utils/adt/varbit.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7
Message templates
ERROR · message.0
Primary
bit string length %d does not match type bit(%d)
ERROR · message.bit-and
Primary
cannot AND bit strings of different sizes
ERROR · message.bit-or
Primary
cannot OR bit strings of different sizes
ERROR · message.bit-xor
Primary
cannot XOR bit strings of different sizes
Reproduction & repair cases
No reproduction case is attached to this condition.
Recorded runtime evidence
No runtime observation is attached to this entry.
Definition snapshot: english-manuals:8c594f1de2028cf061f2e321aae… · English manual source