22P03
PostgreSQLERRORNotableData ExceptionHIGH confidence

invalid binary representation

What this means

SQLSTATE 22P03 is a Postgres-specific error raised when a value supplied in binary format (e.g., via binary COPY or binary protocol parameter binding) does not have a valid binary representation for the expected data type.

Why it happens
  1. 1Sending binary-format parameter data that does not match the wire format expected for the target type
  2. 2Binary COPY data containing malformed type representations
How to reproduce

Binary COPY with malformed type data.

trigger — this will error
trigger — this will error
COPY my_table FROM STDIN WITH (FORMAT binary);
-- binary stream contains invalid type bytes

expected output

ERROR:  invalid binary representation

Fix 1

Use text format COPY for debugging binary format issues

WHEN When diagnosing 22P03 errors from binary COPY operations.

Use text format COPY for debugging binary format issues
COPY my_table FROM STDIN WITH (FORMAT text);

Why this works

Text format COPY is easier to inspect and debug. Switch back to binary only after confirming the data is valid.

Fix 2

Verify driver binary encoding against Postgres type documentation

WHEN When using binary protocol bindings in a custom driver or tool.

Why this works

Check the Postgres frontend/backend protocol documentation for the exact binary wire format of the target type.

Sources
Official documentation ↗

Class 22 — Data Exception (Postgres-specific)

Postgres Protocol Binary Format

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

← All PostgreSQL errors