PostgreSQL import problem
Diagnose PostgreSQL COPY CSV Import Errors
Prepare a CSV for PostgreSQL COPY by checking headers, delimiters, null rules, encoding and rejected field values.
Use the matching tool
CSV Diagnostic
What the error actually means
PostgreSQL COPY has explicit CSV options for the delimiter, header, quote, escape, null representation and encoding. A structurally valid CSV can still fail when a value cannot be converted to the destination column type. PostgreSQL CSV also distinguishes an unquoted empty field from a quoted empty string under its default null rules.
Likely causes
- The COPY delimiter or encoding does not match the file.
- The header order differs from the target column list.
- An empty string is being interpreted differently from NULL.
- A date, number or boolean value violates the destination type.
Explicit COPY contract
Problem
COPY target FROM file with implicit defaultsCorrect pattern
COPY target(cols) FROM file WITH (FORMAT csv, HEADER true, ENCODING 'UTF8')A safe repair workflow
- 1Run a CSV structural diagnostic before touching the database.
- 2Define the target column list and COPY options explicitly.
- 3Load into a staging table when values need normalization.
- 4Reconcile inserted and rejected rows before moving data into production tables.
How to verify the result
A file that downloads successfully is not automatically a correct file. Check the result at both the structural and business-data levels:
- Header names and order match the specified columns.
- Null and empty-string cases behave as intended.
- Date and numeric ranges are plausible after import.
- Source, inserted and rejected counts reconcile.
Read the deeper guides
Official references
Platform requirements and technical standards can change. These are the primary references used for this page.