【问题标题】:Trouble importing .csv file导入 .csv 文件时遇到问题
【发布时间】:2020-09-04 12:42:20
【问题描述】:

请原谅我的无知,我对编码/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”或“NO”(带引号)。
nav 列设置为 Character Varying (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).';

您还需要知道什么来提供帮助吗?

【问题讨论】:

  • 显然您的 nav 列被定义为 character varying[2] 而不是 character varying(2) - 请注意方括号与括号
  • 对不起,这只是我的打字错误。我在设置列时使用属性中的 pgAdmin4 定义了列,所以我很确定这是正确的。我会尝试找到相应的 SQL 语句。
  • CREATE TABLE 语句和文件中的违规行会有所帮助。
  • 我添加了 create table 语句...我想。关于文件中的违规行,我不确定您在寻找什么。有问题的值写在原始问题中。
  • 这个:ERROR: malformed array literal: "3D" DETAIL: Array value must start with "{" or dimension information.,表示nav 被定义为character varying[2](一个数组)。

标签: arrays postgresql


【解决方案1】:

您错误地将列定义为数组,可能是使用

nav character varying[2]

你的意思

nav character varying(2)

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-28
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 2016-04-06
    • 2016-04-02
    • 2021-11-27
    • 2021-04-23
    相关资源
    最近更新 更多