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

后端 未结 3 965
名媛妹妹
名媛妹妹 2021-02-13 03:24

I have csv file that has contents like this:

10,53073,0,0,\'Y\',\'2008-05-30 21:46:55\',0,\'2008-05-30 21:48:04\',0,53071,2

I want to load the

相关标签:
3条回答
  • 2021-02-13 04:01

    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'\'';
    
    0 讨论(0)
  • 2021-02-13 04:14

    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;
    
    0 讨论(0)
  • 2021-02-13 04:24

    Never mind, I got the answer:

    COPY my_table FROM 'c:\downloads\file.csv' DELIMITERS ',' CSV QUOTE '''';
    
    0 讨论(0)
提交回复
热议问题