我有一个表,其列的类型为“带时区的时间戳”
我正在使用此命令从文件导入数据
db=# COPY "temperature" FROM 'd:\data\PostgresImport\TEMPLOG.CSV' DELIMITER ',' CSV;
我收到此错误
ERROR: malformed array literal: "2009-01-05 18:40:00 z"
DETAIL: Array value must start with "{" or dimension information.
CONTEXT: COPY temperature, line 1, column timestamp: "2009-01-05 18:40:00 z"
我尝试重新格式化源数据以将时区显示为+0000,但是仍然出现相同的错误:
ERROR: malformed array literal: "2009-01-05 18:40:00+0000"
DETAIL: Array value must start with "{" or dimension information.
CONTEXT: COPY temperature, line 1, column timestamp: "2009-01-05 18:40:00+0000"
列名不能为“ timestamp”-显然是保留字。创建表时,它会导致诸如此类的奇怪错误,而不是在创建表时将其标记为保留。
通过将列名更改为“ datetimestamp”,COPY FROM命令可以完美地工作。 (使用“ 2009-01-05 18:40:00 + 0000”格式的时间戳记)
db=# COPY "temperature" FROM 'd:\data\PostgresImport\TEMPLOG.CSV' DELIMITER ',' CSV;
COPY 595896
db=#
还要注意:当我用“ timestamp”列创建表时,显然类型是作为数组创建的:
Table "public.temperature"
Column | Type | Collation | Nullable | ------------------+----------------------------+-----------+----------+------
timestamp | timestamp with time zone[] | | |
当我使用“ datetimestamp”重新创建表时,该列不再是数组:
Table "public.temperature"
Column | Type | Collation | Nullable |
------------------+--------------------------+-----------+----------+--
datetimestamp | timestamp with time zone | | |