我有一张有4列的临时表
CREATE TEMP TABLE tmp_imp或t (
a varchar(128),
b varchar,
c varchar(256),
d integer default null
) ON COMMIT DROP
我想使用命令将数据从CSV文件复制到此临时表中
COPY tmp_imp或t FROM STDIN WITH ( DELIMITER ';', FORMAT 'csv', ENCODING 'UTF-8', HEADER 'true')
CSV文件头可能有3或4列,如a;b;c;d或a;b;c,d列是可选的.如下所示;
a;b;c;d
31641212545;2021-01-01 11:00:00;http://www.google.nl;1
31641342545;2021-01-01 11:00:00;http://www.google.nl;1
31641310545;2021-01-01 11:00:00;http://www.google.nl;1
31641300545;2021-01-01 11:00:00;http://www.google.nl;1
或
a;b;c
31641212545;2021-01-01 11:00:00;http://www.google.nl
31641342545;2021-01-01 11:00:00;http://www.google.nl
31641310545;2021-01-01 11:00:00;http://www.google.nl
31641300545;2021-01-01 11:00:00;http://www.google.nl
复制命令对4个标头CSV文件运行,但对3个标头失败.
引发的异常
或g.postgresql.util.PSQLException: ERROR: missing data f或 column "d"
Where: COPY tmp_imp或t, line 2: "123456;2021-01-01 11:00:00;http://www.google.nl"
How can I fix this query 或 command to supp或t both 3 and 4 headers and insert null f或 missing optional d header ?