PG
PRO
22P03ERRORTier 2 — Caution✅ HIGH confidence

invalid binary representation

Category: Data ExceptionVersions: All Postgres versions

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
COPY my_table FROM STDIN WITH (FORMAT binary);
-- binary stream contains invalid type bytes
ERROR: invalid binary representation

Fix 1: Use text format COPY for debugging binary format issues

When diagnosing 22P03 errors from binary COPY operations.

fix
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 using binary protocol bindings in a custom driver or tool.

fix

Why this works

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

Sources

📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html

🔧 Source ref: Class 22 — Data Exception (Postgres-specific)

📖 Further reading: Postgres Protocol Binary Format

Confidence assessment

✅ HIGH confidence

Postgres-specific error for binary format validation. Stable across versions.

See also

📄 Reference pages

COPYBinary FormatPostgres Protocol
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →