NULL值处理
最近更新时间: 2025-02-18 16:02:00
postgres=# \! cat /data/pgxz/t.txt
1 TDSQL PG NULL 7
2 pg'", xc% 2017-10-28 18:24:05.643102 3
3 pgxz 2017-10-28 18:24:05.645691 NULL
postgres=# copy t from '/data/pgxz/t.txt' (null 'NULL');
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)
#将文件中的NULL字符串当成NULL值处理,SQL SERVER导出来的文件中把NULL值替换成字符串NULL,所以入库时可以这样处理一下,注意字符串是区分大小写,如下面语句导入数据就会出错
postgres=# copy t from '/data/pgxz/t.txt' (null 'null');
ERROR: invalid input syntax for type timestamp: "NULL"
CONTEXT: COPY t, line 1, column f3: "NULL"