22026
PostgreSQLERRORNotableData ExceptionHIGH confidence

string data length mismatch

What this means

SQLSTATE 22026 is raised when a string value has a length that does not match the expected or declared length — for example, when a CHAR(n) value being compared or converted has a different byte length than required.

Why it happens
  1. 1A string value does not match the required fixed length in a context that mandates exact length
  2. 2Multi-byte encoding means a character string has more bytes than characters, conflicting with a byte-length check
How to reproduce

String length mismatch in a fixed-length context.

expected output

ERROR:  string data length mismatch

Fix

Ensure string values match the required length or use variable-length types

WHEN When working with CHAR(n) columns or fixed-length string operations.

Ensure string values match the required length or use variable-length types
-- Use VARCHAR(n) instead of CHAR(n) to avoid length padding issues:
ALTER TABLE codes ALTER COLUMN code TYPE VARCHAR(10);

Why this works

VARCHAR is more flexible than CHAR for variable-length content. CHAR pads with spaces to the fixed length, which can cause comparison issues.

Sources
Official documentation ↗

Class 22 — Data Exception

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors