Postgres COPY command with literal delimiter

橙三吉。 提交于 2021-02-08 03:41:25

问题


I was trying to import a CSV file into a PostgreSQL table using the COPY command. The delimiter of the CSV file is comma (,). However, there's also a text field with a comma in the value. For example:

COPY schema.table from '/folder/foo.csv' delimiter ',' CSV header

Here's the content of the foo.csv file:

Name,Description,Age
John,Male\,Tall,30

How to distinguish between the literal comma and the delimiter?

Thanks for your help.


回答1:


To have the \ to be recognized as a escape character it is necessary to use the text format

COPY schema.table from '/folder/foo.csv' delimiter ',' TEXT

But then it is also necessary to delete the first line as the HEADER option is only valid for the CSV format.



来源:https://stackoverflow.com/questions/26160816/postgres-copy-command-with-literal-delimiter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!