SQLSTATE 22P04 ERROR Class 22: Data Exception

bad_copy_file_format extra data after last expected column — 22P04

PostgreSQL error "extra data after last expected 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 contained more fields than the target column list. PostgreSQL raises SQLSTATE 22P04 (bad_copy_file_format).

  • A data row has too many columns.
  • Common with the wrong delimiter or unquoted embedded delimiters.
  • The row count exceeds the expected columns.

What the server log shows

ERROR:  extra data after last expected column
CONTEXT:  COPY orders, line 42: "1,2024-01-01,42.00,extra"

Why PostgreSQL raises this — what the manual says

the COPY reference (File Formats):

“For COPY FROM, each field in the file is inserted, in order, into the specified column.”

COPY expects each row to have exactly as many fields as the target column list. A row with more fields (often from a wrong delimiter or an unescaped delimiter in data) doesn’t align, so PostgreSQL reports 22P04.

Common causes

  • Wrong DELIMITER for the file.
  • Unquoted delimiter characters inside a data value.
  • Mismatch between the file and the table’s column list.

How to fix it

  1. Set the correct DELIMITER (e.g. CSV with commas).
  2. Quote fields containing the delimiter, or use FORMAT csv with proper quoting.
  3. Align the COPY column list with the file’s columns.

Related & next steps

Reference: PostgreSQL 18 — COPY.

Was this helpful?