csv header忽略首行
最近更新时间: 2025-02-18 16:02:00
postgres=# \! cat /data/pgxz/t.csv;
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,
postgres=# copy t from '/data/pgxz/t.csv' (format 'csv');
ERROR: invalid input syntax for integer: "f1"
CONTEXT: COPY t, line 1, column f1: "f1"
postgres=# copy t from '/data/pgxz/t.csv' (format 'csv',header true);
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)
如果不忽略首行,则系统会把首行当成数据,造成导入失败。