invalid binary representation
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.
- 1Sending binary-format parameter data that does not match the wire format expected for the target type
- 2Binary COPY data containing malformed type representations
Binary COPY with malformed type data.
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.
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.
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