SQLSTATE 22P04 ERROR Class 22: Data Exception

bad_copy_file_format missing data for column “…” — 22P04

PostgreSQL error "missing data for column "…"" (SQLSTATE 22P04): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A COPY input row had fewer fields than the target column list, leaving a column without data. PostgreSQL raises SQLSTATE 22P04 (bad_copy_file_format).

  • A data row has too few columns.
  • The named column received no value.
  • Common with the wrong delimiter or truncated rows.

What the server log shows

ERROR:  missing data for column "amount"
CONTEXT:  COPY orders, line 42: "1,2024-01-01"

Why PostgreSQL raises this — what the manual says

As the COPY reference (File Formats) explains:

A COPY input row supplied fewer fields than there are target columns, so at least one column had no data; every row must contain a value (or the configured NULL marker) for each column in the column list.

COPY requires each row to supply a value for every target column. A row with fewer fields leaves a column unfilled, so PostgreSQL reports 22P04 naming that column.

Common causes

  • Wrong DELIMITER so fields aren’t split correctly.
  • Truncated or malformed rows in the input.
  • The file has fewer columns than the table’s column list.

How to fix it

  1. Use the correct DELIMITER and quoting.
  2. Fix truncated rows, or supply all required columns.
  3. List only the columns present in the file in the COPY column list.

Related & next steps

Reference: PostgreSQL 18 — COPY.

Was this helpful?