指定导入文件格式

最近更新时间: 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');
COPY 3
TRUNCATE TABLE
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');    
COPY 3
postgres=# truncate table t;
TRUNCATE TABLE
postgres=# \! od -c /data/pgxz/t.bin
0000000   P   G   C   O   P   Y  \n 377  \r  \n  \0  \0  \0  \0  \0  \0
0000020  \0  \0  \0  \0 004  \0  \0  \0 004  \0  \0  \0 001  \0  \0  \0
0000040 005   T   b   a   s   e 377 377 377 377  \0  \0  \0 004  \0  \0
0000060  \0  \a  \0 004  \0  \0  \0 004  \0  \0  \0 002  \0  \0  \0 016
0000100   p   g   '   "   ,                           x   c   %  \0  \0
0000120  \0  \b  \0 001 377 236   G   w 213   ^  \0  \0  \0 004  \0  \0
0000140  \0 003  \0 004  \0  \0  \0 004  \0  \0  \0 003  \0  \0  \0 004
0000160   p   g   x   z  \0  \0  \0  \b  \0 001 377 236   G   w 225   {
0000200 377 377 377 377 377 377
0000206
postgres=# copy t from '/data/pgxz/t.bin' (format 'binary');
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)