psql copy 命令不会正确解释 NULL 值
psql copy command will not interpret NULL values properly
我正在尝试将值从 csv(使用 headers)复制到 table。我看过 this answer 说要指定 NULL 值,但它似乎对我没有影响。这是我的:
CREATE TABLE stops
(
stop_id text PRIMARY KEY,
--stop_code text NULL,
stop_name text NOT NULL,
--stop_desc text NULL,
stop_lat double precision NOT NULL,
stop_lon double precision NOT NULL,
zone_id integer NULL,
stop_url text NULL,
location_type boolean NULL,
parent_station text NULL
);
\copy stops from './stops.txt' with csv header NULL AS ''
我也试过像这样使用 \N
字符:
\copy stops from './stops.txt' with csv header NULL AS '\N'
不过好像没有效果
我也尝试过尝试找到 here 的解决方案,它看起来像这样:
\copy agency from './agency.txt' WITH (FORMAT csv header, FORCE_NULL(zone_id))
但这似乎在 csv_header
部分引发语法错误。
版本为 9.6。
这是 csv 的摘录:
stop_id,stop_name,stop_lat,stop_lon,zone_id,stop_url,location_type,parent_station
"de:07334:1714:1:1","Wörth Alte Bahnmeisterei","49.048742345982","8.26622538039577","","","","Parent1714"
"de:07334:1714:1:2","Wörth Alte Bahnmeisterei","49.0484420719247","8.26673742010779","","","","Parent1714"
"de:07334:1721:1:1","Maximiliansau Eisenbahnstraße","49.0373071007148","8.29789997731824","","","","Parent1721"
"de:07334:1721:2:2","Maximiliansau Eisenbahnstraße","49.0371363175998","8.29896897250649","","","","Parent1721"
But this seems to throw a syntax error at the csv_header part.
在 csv 后面加一个逗号:
\copy agency from './agency.txt' WITH (FORMAT csv, HEADER, FORCE_NULL(zone_id,location_type))
显然,当使用空字符串指定 NULL 时,非文本列需要 FORCE_NULL
。
我正在尝试将值从 csv(使用 headers)复制到 table。我看过 this answer 说要指定 NULL 值,但它似乎对我没有影响。这是我的:
CREATE TABLE stops
(
stop_id text PRIMARY KEY,
--stop_code text NULL,
stop_name text NOT NULL,
--stop_desc text NULL,
stop_lat double precision NOT NULL,
stop_lon double precision NOT NULL,
zone_id integer NULL,
stop_url text NULL,
location_type boolean NULL,
parent_station text NULL
);
\copy stops from './stops.txt' with csv header NULL AS ''
我也试过像这样使用 \N
字符:
\copy stops from './stops.txt' with csv header NULL AS '\N'
不过好像没有效果
我也尝试过尝试找到 here 的解决方案,它看起来像这样:
\copy agency from './agency.txt' WITH (FORMAT csv header, FORCE_NULL(zone_id))
但这似乎在 csv_header
部分引发语法错误。
版本为 9.6。
这是 csv 的摘录:
stop_id,stop_name,stop_lat,stop_lon,zone_id,stop_url,location_type,parent_station
"de:07334:1714:1:1","Wörth Alte Bahnmeisterei","49.048742345982","8.26622538039577","","","","Parent1714"
"de:07334:1714:1:2","Wörth Alte Bahnmeisterei","49.0484420719247","8.26673742010779","","","","Parent1714"
"de:07334:1721:1:1","Maximiliansau Eisenbahnstraße","49.0373071007148","8.29789997731824","","","","Parent1721"
"de:07334:1721:2:2","Maximiliansau Eisenbahnstraße","49.0371363175998","8.29896897250649","","","","Parent1721"
But this seems to throw a syntax error at the csv_header part.
在 csv 后面加一个逗号:
\copy agency from './agency.txt' WITH (FORMAT csv, HEADER, FORCE_NULL(zone_id,location_type))
显然,当使用空字符串指定 NULL 时,非文本列需要 FORCE_NULL
。