自定义escape字符
最近更新时间: 2025-02-18 16:02:00
postgres=# \! cat /data/pgxz/t.csv
1,TDSQL PG,,7
2,"pg'@", xc%",2017-10-28 18:24:05.643102,3
3,pgxz,2017-10-28 18:24:05.645691,
postgres=# copy t from '/data/pgxz/t.csv' (format 'csv');
ERROR: unterminated CSV quoted field
CONTEXT: COPY t, line 4: "2,"pg'@", xc%",2017-10-28 18:24:05.643102,3
3,pgxz,2017-10-28 18:24:05.645691,
"
#不指定escape字符时,系统默认就是双写的quote字符,如双倍的“双引号”
postgres=# copy t from '/data/pgxz/t.csv' (format 'csv',escape '@');
COPY 3
postgres=# select * from t;
f1 | f2 | f3 | f4
----+----------------+----------------------------+----
1 | TDSQL PG | | 7
2 | pg'", xc% | 2017-10-28 18:24:05.643102 | 3
3 | pgxz | 2017-10-28 18:24:05.645691 |
(3 rows)
postgres=#