SQLSTATE 22026Severity lowLab verified

Incident brief

String data length mismatch

A bit string value was stored into a bit(n) column whose length didn't exactly match n. PostgreSQL rejected the write instead of guessing how to fit it.

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Reviewed by Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What
String data length mismatch
What triggers it
Create a table with a fixed-length bit(3) column.
The fix
Supply a bit string whose length exactly matches the column's declared length.
Proof
Reproduced on PostgreSQL 16.14 → Inserting a 2-bit value into a bit(3) column was rejected with SQLSTATE 22026, naming both the supplied length and the declared length. The session was unaffected afterward.

The fix

What to do right now

The immediate, application-level response to this error.

  • Supply a bit string whose length exactly matches the column's declared length.
  • If you intentionally want truncation/padding instead of an error, that's a different, explicit operation — see the counterexample for what it actually does and why it's risky.
  • Prefer bit varying(n) over bit(n) if the true length legitimately varies.
Fix — SQL
CREATE TABLE bitflags (a bit(3));
INSERT INTO bitflags VALUES (B'101'); -- exactly 3 bits

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 16.14
Last verified
2026-07-16 (Docker lab, PostgreSQL 16.14)
Reviewed by
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed