
PostgreSQL COPY Error Extra Data After Last Expected Column
The COPY error means a row has more fields than the table has columns. See the four usual causes, how to find the line, and the fix for each one.
Everything you need to level up your coding skills.

The COPY error means a row has more fields than the table has columns. See the four usual causes, how to find the line, and the fix for each one.

Skip the header, or better, check it. See what HEADER true, HEADER match and a column list do, and the errors when the file and the table disagree.

The two commands differ in which machine reads the file. See the permission errors, the path errors and the timings, and choose the one that fits.

The COPY command in practice: the options that matter, the two ways to feed it, what its row count means, and why one bad value undoes the whole load.

Load a CSV into PostgreSQL with COPY, see what makes it fast, and learn what each failure means, with a script that loads in one transaction.

Find the lines and bytes that break a UTF-8 load with iconv, isutf8, grep or a short Python script, and see how PostgreSQL and DuckDB report them.

MySQL utf8 columns hold three bytes per character, so an emoji becomes a question mark during a CSV load with only a warning. See the fix and the checks.

Question marks in a CSV are lost data, not a display bug. See where the substitution happens, count the damage and decide whether the export is broken.

A NUL byte can cut a PostgreSQL load short while Python keeps it. Find them with grep, strip them from 130 MB in under a second, and keep tabs and newlines.

Excel on Windows often shows UTF-8 accents as à symbols. Add a BOM when you write the file, or import it with the right encoding, and check the bytes first.

Repair text like José inside a CSV by reversing the wrong decode, with ftfy or two lines of Python, and learn which garbling can never be undone.

Convert a legacy CSV to UTF-8 with iconv or Python, choose between Latin 1 and Windows 1252, and handle the five bytes Windows 1252 leaves undefined.
We send one email when a new article is published. No spam.