Is it possible to turn off quote processing in the Postgres COPY command with CSV format?

前端 未结 3 1789
萌比男神i
萌比男神i 2020-12-14 07:53

I have CSV files, tab-separated, fields not wrapped in quotes, where field data can contain characters like single quotes, double quotes, pipes and backslashes.

3条回答
  •  抹茶落季
    2020-12-14 08:36

    (Added as a new answer since I don't have the reputation yet to comment.)

    For the record, since I've been struggling with the same issue, you can use tr to remove \b, instead of just hoping it's not in your text anywhere.

    tr -d '\010' < filename.csv > newfile.csv
    

    (Using that \010 is the octal representation of \b).

    Since COPY supports reading from STDIN, you can ease the I/O impact by piping tr's output:

    cat filename.csv | tr -d '\010' | COPY  FROM STDIN WITH CSV DELIMITER E'\t' QUOTE E'\b' NULL AS '';
    

提交回复
热议问题