PostgreSQL COPY CSV errors: what they mean and how to fix them

Updated November 22, 2026

COPY is the fastest way to load a CSV into PostgreSQL, and it stops at the first bad row. The error tells you the line number and the column. This page lists the errors you’ll meet most often, what each one means and the option or fix that gets past it.

A working starting point for a typical file with a header row:

COPY customers (id, name, email, signup_date)
FROM '/path/to/customers.csv'
WITH (FORMAT csv, HEADER true);

could not open file … for reading

ERROR:  could not open file "/Users/me/customers.csv" for reading: No such file or directory

COPY … FROM 'file' reads the file on the database server, not on your computer, and needs superuser rights or the pg_read_server_files role. If the file is on your machine, use psql’s \copy, which reads it locally and sends it over the connection:

\copy customers FROM 'customers.csv' WITH (FORMAT csv, HEADER true)

invalid input syntax for type integer: "id"

The header row is being loaded as data. Add HEADER true. On PostgreSQL 15 and later, HEADER match also checks that the header names match the table’s columns.

extra data after last expected column / missing data for column

A row has more or fewer fields than the column list. Either the file uses another separator (add DELIMITER ';' for semicolon files) or a value contains a comma, quote or line break that isn’t quoted properly. The “Expected N fields” guide shows how to find and fix those rows.

unterminated CSV quoted field

A value opens with " and never closes, so PostgreSQL reads to the end of the file looking for it. Look a few lines above the reported line for a stray quote, for example 55" TV. Inside a quoted value, a quote has to be written twice: "55"" TV".

invalid byte sequence for encoding "UTF8": 0xe9

The file isn’t UTF-8. 0xe9 is é in Windows-1252, the encoding Excel uses for plain CSV on Western systems. Tell COPY the real encoding:

COPY customers FROM '/path/to/customers.csv'
WITH (FORMAT csv, HEADER true, ENCODING 'WIN1252');

Or convert the file first with iconv -f WINDOWS-1252 -t UTF-8. More on this in the CSV encoding guide.

invalid input syntax for type integer: ""

In CSV format, an empty unquoted field becomes NULL, but an empty quoted field ("") is an empty string, which isn’t a valid number or date. Many exports quote every field. Tell PostgreSQL to treat empty strings in those columns as NULL:

COPY orders FROM '/path/to/orders.csv'
WITH (FORMAT csv, HEADER true, FORCE_NULL (quantity, shipped_at));

invalid input syntax for type numeric: "1.299,00"

Thousands separators, currency signs and decimal commas (19,99) aren’t valid numbers. Load the column into a text column of a staging table, then convert it with SQL:

INSERT INTO products (sku, price)
SELECT sku, replace(replace(price_text, '.', ''), ',', '.')::numeric
FROM staging_products;  -- European format: 1.299,00

For US-style values like 1,299.00, remove the commas instead: replace(price_text, ',', '')::numeric.

date/time field value out of range: "31/12/2026"

PostgreSQL reads ambiguous dates as month first by default, so day 31 becomes month 31. Set the date order for the session before running COPY:

SET datestyle = 'ISO, DMY';

value too long for type character varying(50)

A value is longer than the column allows. Widen the column, or load into a staging table first and find the long values with WHERE length(name) > 50. Sometimes the “long value” is really a broken row where two fields ran together because of a quoting problem.

A pattern that avoids most of this

Load the CSV into a staging table where every column is text. That load almost never fails on types. Then clean and cast with SQL, where you can see the bad values instead of stopping at the first one.

To catch structural problems before you run COPY at all (wrong encoding, a stray BOM, unclosed quotes, rows with the wrong number of columns), drop the file into CSVCheck. It runs in your browser and shows the line numbers.

More CSV guides