The correct COPY command to load postgreSQL data from csv file that has single-quoted data? The correct COPY command to load postgreSQL data from csv file that has single-quoted data? sql sql

The correct COPY command to load postgreSQL data from csv file that has single-quoted data?


Double single quotes (if standard_conforming_strings is on, see the docs)

COPY my_table FROM 'c:\downloads\file.csv' DELIMITERS ',' CSV QUOTE '''';

or use the non-standard PostgreSQL-specific escape string:

COPY my_table FROM 'c:\downloads\file.csv' DELIMITERS ',' CSV QUOTE E'\'';


Some other people who are experiencing this error may want to check the file to see if it contains a header on the first line. While it wasn't the problem in your case, it is worth noting the way to work around it:

COPY my_table FROM 'c:\downloads\file.csv' WITH DELIMITER ',' CSV HEADER;


Never mind, I got the answer:

COPY my_table FROM 'c:\downloads\file.csv' DELIMITERS ',' CSV QUOTE '''';