I'm trying to import a CSV file into a table in Postgres, and it's bombing out on the first date field. The dates are in the format dd/mm/yyyy
and there isn't a date in the field in question in the CSV.
As such I'm using the following:
set datestyle = 'ISO,DMY';
\copy companies_house_snapshot
FROM 'BasicCompanyDataAsOneFile-2017-04-01.csv'
WITH DELIMITER ',' CSV HEADER NULL AS '';
Which I thought should be sufficient, the error message is:
ERROR: invalid input syntax for type date: "" CONTEXT: COPY companies_house_snapshot, line 2, column dissolution_date: ""
Where dissolution_date
is nullable and in the CSV as ""
I'm using PostgreSQL 9.5.6 on Ubuntu 16.04
Where am I going wrong?
If I use '""'
as NULL
, I get:
ERROR: CSV quote character must not appear in the NULL specification
CSV
andNULL AS '""'
is possible ; butHEADER
is not possible withoutCSV
NULL AS '""'
with theCSV
option, but you can without it. But you useHEADER
which could be use only withCSV
. You have to choose betweenNULL AS '""'
andHEADER
. You can preprocess your file to remove the first line, by example.