使用 psql copy 导入带有时间戳列 (dd.mm.yyyy hh.mm.ss) 的 .csv [英] Importing .csv with timestamp column (dd.mm.yyyy hh.mm.ss) using psql copy

查看:27
本文介绍了使用 psql copy 导入带有时间戳列 (dd.mm.yyyy hh.mm.ss) 的 .csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 psql COPY 命令(不是 SQL COPY)将 .csv 文件中的数据导入 postgresql 9.2 数据库.

I'm trying to import data from a .csv file into a postgresql 9.2 database using the psql COPY command (not the SQL COPY).

输入 .csv 文件包含一个带有 dd.mm.yyyy hh.mm.ss 格式的时间戳的列.

The input .csv file contains a column with a timestamp in the dd.mm.yyyy hh.mm.ss format.

我已使用 DMY 将数据库日期样式设置为.

I've set the database datestyle to DMY using.

set datestyle 'ISO,DMY'

不幸的是,当我运行 COPY 命令时:

Unfortunately, when I run the COPY command:

COPY gc_test.trace(numpoint,easting,northing,altitude,numsats,pdop,timestamp_mes,duration,ttype,h_error,v_error) 
FROM 'C:data.csv' WITH DELIMITER ';' CSV HEADER ENCODING 'ISO 8859-1'

我收到此错误:

错误:日期/时间字段值超出范围:16.11.2012 07:10:06"

ERROR: date/time field value out of range: "16.11.2012 07:10:06"

提示:也许您需要不同的日期样式";设置.

HINT: Perhaps you need a different "datestyle" setting.

上下文:复制跟踪,第 2 行,列 timestamp_mes:16.11.2012 07:10:06"

CONTEXT: COPY trace, line 2, column timestamp_mes: "16.11.2012 07:10:06"

日期样式有什么问题?

推荐答案

你试过设置 服务器datestyle设置?

SET datestyle = 'ISO,DMY';

您正在使用 psql 元命令 copy,这意味着输入文件是客户端本地的.但仍然是服务器必须强制输入匹配的数据类型.

You are using the psql meta-command copy, which means the input file is local to the client. But it's still the server who has to coerce the input to matching data-types.

更一般地说,与 psql 元命令 copy 不同,它在服务器上调用 COPY 并与之密切相关.. 我引用 关于set的手册:

More generally, unlike the psql meta-command copy which invokes COPY on the server and is closely related to it .. I quote the manual concerning set:

注意:此命令与 SQL 命令 SET 无关.

Note: This command is unrelated to the SQL command SET.

这篇关于使用 psql copy 导入带有时间戳列 (dd.mm.yyyy hh.mm.ss) 的 .csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆