简体   繁体   English

Psql:使用 \\copy from csv 导入日期列时出错

[英]Psql: error to import date column using \copy from csv

My csv file is something like this: pmsbcod;ansbfmues;paracod AB070001;2018-10-29;124TMB ...我的 csv 文件是这样的: pmsbcod;ansbfmues;paracod AB070001;2018-10-29;124TMB ...

Using \\copy metacommand I always have the error ERROR: invalid input syntax for type timestamp with time zone: "0.0" I don't have problems importing other csv files without timestamp columns使用 \\copy metacommand 我总是有错误 ERROR: invalid input syntax for type timestamp with time zone: "0.0" 我在导入没有时间戳列的其他 csv 文件时没有问题

I have tried with several date formats (dd/mm/yyyy, yyyy-mm-dd, yyyy-mm-dd hh:mm:ss, yyyy-mm-dd hh:mm:ss+0.1..) but the error messages is always the same;我尝试了几种日期格式(dd/mm/yyyy、yyyy-mm-dd、yyyy-mm-dd hh:mm:ss、yyyy-mm-dd hh:mm:ss+0.1..)但错误消息总是一样的; or ERROR: invalid input syntax for type timestamp with time zone: "2018-10-29 00:00:00+0.1" with this datetime format.或错误:带有时区的时间戳类型的无效输入语法:“2018-10-29 00:00:00+0.1”,使用此日期时间格式。

My server date style is ISO, DMY -show datestyle;- In other timestamp columns that I have imported with a python script the date format is 2017-03-21 00:00:00;我的服务器日期样式是 ISO,DMY -show datestyle;- 在我用 python 脚本导入的其他时间戳列中,日期格式是 2017-03-21 00:00:00; in the python script I can execute something like cursor.execute('insert into table values (%s, %s, %s)', ('AB070001','2018-10-29','124TMB') with any problems在 python 脚本中,我可以执行类似 cursor.execute('insert into table values (%s, %s, %s)', ('AB070001','2018-10-29','124TMB') 的任何问题

I'm executing psql from console with code page 1252我正在使用代码页 1252 从控制台执行 psql

Thanks in advance提前致谢

The error is not related with date format but with the number of columns in csv -not in the example, but in the real case-该错误与日期格式无关,而与 csv 中的列数有关 - 不是在示例中,而是在实际情况中 -

When I write the column names in the \\copy metacommand I could catch the cause of the error当我在 \\copy metacommand 中写入列名时,我可以找出错误的原因

I'm so sorry for wasting your time我很抱歉浪费你的时间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM