使用delimiter指定列与列之间的分隔符
最近更新时间: 2025-02-18 16:02:00
postgres=# \! cat /data/pgxz/t.txt
1%TDSQL PG%\N%7
2%pg'", xc\%%2017-10-28 18:24:05.643102%3
3%pgxz%2017-10-28 18:24:05.645691%\N
postgres=# copy t from '/data/pgxz/t.txt' (format 'text',delimiter '%');
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=# \! 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=# truncate table t;
TRUNCATE TABLE
postgres=# copy t from '/data/pgxz/t.csv' (format 'csv',delimiter '%');
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)