从 CSV 加载 PostgreSQL table,数据在括号之间带有逗号
Load PostgreSQL table from CSV with data with commas between brackets
我得到了一些 CSV 数据,我需要将其加载到 PostgreSQL table 中,格式如下:
7227, {text with, commas}, 10.0, 3.0, text with no commas
我希望我的 table 行显示为:
7227 | text with, commas | 10.0 | 3.0 | text with no commas
如何使用 COPY 并让它忽略括号之间的逗号?
我试图避免预处理文件,尽管这是一个选项。
恐怕您必须编辑该文件。这个格式应该没问题:
7227, "text with, commas", 10.0, 3.0, text with no commas
或者
7227, text with\, commas, 10.0, 3.0, text with no commas
根据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.
我得到了一些 CSV 数据,我需要将其加载到 PostgreSQL table 中,格式如下:
7227, {text with, commas}, 10.0, 3.0, text with no commas
我希望我的 table 行显示为:
7227 | text with, commas | 10.0 | 3.0 | text with no commas
如何使用 COPY 并让它忽略括号之间的逗号?
我试图避免预处理文件,尽管这是一个选项。
恐怕您必须编辑该文件。这个格式应该没问题:
7227, "text with, commas", 10.0, 3.0, text with no commas
或者
7227, text with\, commas, 10.0, 3.0, text with no commas
根据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.