Ignore quotation marks when importing a CSV file into PostgreSQL?

前端 未结 3 1524
太阳男子
太阳男子 2021-02-19 12:41

I\'m trying to import a tab-delimited file into my PostgreSQL database. One of the fields in my file is a \"title\" field, which occasionally contains actual quotation marks. Fo

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-19 12:52

    I struggled with the same error and a few more. Finally gathering knowledge from few SO questions I came up with the following setup for making COPY TO/FROM successful even for quite sophisticated JSON columns:

    COPY "your_schema_name.yor_table_name" (your, column_names, here) 
    FROM STDIN WITH CSV DELIMITER E'\t' QUOTE '\b' ESCAPE '\';
    --here rows data
    \.
    

    the most important parts:

    • QUOTE '\b' - quote with backspace (thanks a lot @grautur!)
    • DELIMITER E'\t' - delimiter with tabs
    • ESCAPE '\' - and escape with a backslash

提交回复
热议问题