导入.csv文件时遇到问题

时间:2020-09-04 12:42:20

标签: arrays postgresql

请原谅我的无知,我是编码/ postgreSQL的新手。我正在按照书中的说明进行操作,并尝试导入提供的测试数据。下面是我要导入的.csv文件。

SET SESSION datestyle = "ISO, DMY"; COPY main.gps_data(
gps_sensors_code, line_no, utc_date, utc_time, lmt_date, lmt_time, ecef_x,
ecef_y, ecef_z, latitude, longitude, height, dop, nav, validated, sats_used,
ch01_sat_id, ch01_sat_cnr, ch02_sat_id, ch02_sat_cnr, ch03_sat_id,
ch03_sat_cnr, ch04_sat_id, ch04_sat_cnr, ch05_sat_id, ch05_sat_cnr,
ch06_sat_id, ch06_sat_cnr, ch07_sat_id, ch07_sat_cnr, ch08_sat_id,
ch08_sat_cnr, ch09_sat_id, ch09_sat_cnr, ch10_sat_id, ch10_sat_cnr,
ch11_sat_id, ch11_sat_cnr, ch12_sat_id, ch12_sat_cnr, main_vol, bu_vol,
temp, easting, northing, remarks)
FROM
'C:\Users\Documents\SpatialDatabaseBook\tracking_db\data\sensors_data\GSM01438.csv'
WITH (FORMAT csv, HEADER, DELIMITER ';')

我遇到以下错误:

ERROR:  malformed array literal: "3D"
DETAIL:  Array value must start with "{" or dimension information.
CONTEXT:  COPY gps_data, line 2, column nav: "3D"
SQL state: 22P02

我的.csv文件的导航列值为:“ 3D”,“ 2D”或“否”(带引号)。
导航列设置为“字符变化(2)”。

    gps_data_id serial,
gps_sensors_code character varying,
line_no integer,
utc_date date,
utc_time time without time zone,
lmt_date date,
lmt_time time without time zone,
ecef_x integer,
ecef_y integer,
ecef_z integer,
latitude double precision,
longitude double precision,
height double precision,
dop double precision,
nav character varying (2),
validated character varying (3),
sats_used integer,
ch01_sat_id integer,
ch01_sat_cnr integer,
ch02_sat_id integer,
ch02_sat_cnr integer,
ch03_sat_id integer,
ch03_sat_cnr integer,
ch04_sat_id integer,
ch04_sat_cnr integer,
ch05_sat_id integer,
ch05_sat_cnr integer,
ch06_sat_id integer,
ch06_sat_cnr integer,
ch07_sat_id integer,
ch07_sat_cnr integer,
ch08_sat_id integer,
ch08_sat_cnr integer,
ch09_sat_id integer,
ch09_sat_cnr integer,
ch10_sat_id integer,
ch10_sat_cnr integer,
ch11_sat_id integer,
ch11_sat_cnr integer,
ch12_sat_id integer,
ch12_sat_cnr integer,
main_vol double precision,
bu_vol double precision,
temp double precision,
easting integer,
northing integer,
remarks character varying
);
COMMENT ON TABLE main.gps_data
IS 'Table that stores raw data as they come from the sensors (plus the ID of the sensor).';

您还需要帮助吗?

1 个答案:

答案 0 :(得分:0)

您可能错误地将列定义为数组

nav character varying[2]

您的意思

nav character varying(2)

如果表仍然为空,最简单的解决方法是更改​​数据类型,并丢弃所有现有值:

ALTER TABLE main.gps_data
   ALTER nav TYPE character varying(2) USING (NULL);