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
DELIMITERso 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
- Use the correct
DELIMITERand quoting. - Fix truncated rows, or supply all required columns.
- List only the columns present in the file in the COPY column list.
Related & next steps
Reference: PostgreSQL 18 — COPY.
Thanks — noted. This helps keep the database accurate.