在 PostgreSQL / YugabyteDB 中导入 csv 文件时如何转义引号
How to escape quotes when importing csv file in PostgreSQL / YugabyteDB
使用 YugabyteDB 2.5.3.1 (PostgreSQL 11.2)。
我目前有这个 table:
create table bum2(id int, the_t text);
希望将此 "a"bc"
从 csv 文件导入文本列。
尝试使用此 csv 文件:
6,""a""bc""
并且:
\copy bum2 from data.csv WITH (FORMAT csv);
并获得:
yugabyte=# select * from bum2;
id | the_t
----+-------
6 | abc
(1 row)
您可以使用额外的引号来转义引号。下面的 csv 文件有效:
6,"""a""bc"""
yugabyte=# \copy bum2 from data.csv WITH (FORMAT csv);
COPY 1
yugabyte=# select * from bum2;
id | the_t
----+--------
6 | "a"bc"
(1 row)
使用 YugabyteDB 2.5.3.1 (PostgreSQL 11.2)。
我目前有这个 table:
create table bum2(id int, the_t text);
希望将此 "a"bc"
从 csv 文件导入文本列。
尝试使用此 csv 文件:
6,""a""bc""
并且:
\copy bum2 from data.csv WITH (FORMAT csv);
并获得:
yugabyte=# select * from bum2;
id | the_t
----+-------
6 | abc
(1 row)
您可以使用额外的引号来转义引号。下面的 csv 文件有效:
6,"""a""bc"""
yugabyte=# \copy bum2 from data.csv WITH (FORMAT csv);
COPY 1
yugabyte=# select * from bum2;
id | the_t
----+--------
6 | "a"bc"
(1 row)