I use postgres 8.4 and currently trying to import a trivial CSV:
Here is a table:
CREATE TABLE public.sample ( a VARCHAR, b VARCHAR ) WITHOUT OIDS;
and here is a csv file sample:
COPY sample FROM '/tmp/sample.csv' USING DELIMITERS ',';
ERROR: extra data after last expected column CONTEXT: COPY sample, line 1: ""foo","bar, baz""
But, well, CSV parsing is not a rocket science and I would wonder if it is not possible to solve without reformatting the source csv.
PS: the csv comes from 3rd party, I cannot change the format.
PPS: yes, I understand I could pre-process it (change the delimiter manually) before I import it
COPY sample FROM '/tmp/sample.csv' WITH DELIMITER ',' CSV;
Originally taken from https://stackoverflow.com/a/9682174/251311, and documentation page is http://www.postgresql.org/docs/8.4/static/sql-copy.html
Clearly you have a CSV file while you try to import it as text format. Use:
COPY sample FROM '/tmp/sample.csv' FORMAT CSV;
The default delimiter for CSV format is the comma (
,) anyway. More in the manual. Syntax is for current version 9.1. For PostgreSQL 8.4:
COPY sample FROM '/tmp/sample.csv' CSV;
COPY sample FROM '/tmp/sample.csv' WITH FORMAT (CSV, DELIMITER ',', NULL ' ');PJATX 2018-01-29 23:34