问题
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