Load PostgreSQL table from CSV with data with commas between brackets

蹲街弑〆低调 提交于 2019-12-11 13:57:21

问题


I've been given some CSV data I need to load into a PostgreSQL table with the following format:

7227, {text with, commas}, 10.0, 3.0, text with no commas

I want my table rows to appear as:

   7227 | text with, commas | 10.0 | 3.0 | text with no commas

How can I use COPY and get it to ignore commas between the brackets?

I'm trying to avoid pre-processing the file, although that is an option.


回答1:


I'm afraid you'll have to edit the file. This format should be ok:

7227, "text with, commas", 10.0, 3.0, text with no commas

Alternatively

7227, text with\, commas, 10.0, 3.0, text with no commas

according to this principle in the documentation:

Backslash characters (\) can be used in the COPY data to quote data characters that might otherwise be taken as row or column delimiters. In particular, the following characters must be preceded by a backslash if they appear as part of a column value: backslash itself, newline, carriage return, and the current delimiter character.



来源:https://stackoverflow.com/questions/30380040/load-postgresql-table-from-csv-with-data-with-commas-between-brackets

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