简体   繁体   English

表中的日期为dd.mm.yyyy-无法通过csv导入到postgres

[英]Date in table is dd.mm.yyyy - Can't import to postgres via csv

I'm trying to add a .csv to a table in database. 我正在尝试向数据库中的表添加.csv。

All dates in the .csv is in this format dd.mm.yyyy ( 18.10.2017). .csv中的所有日期都采用dd.mm.yyyy (18.10.2017)格式。

I'm importing via pgadmin and always get an invalid input error. 我正在通过pgadmin导入,并且总是收到无效的输入错误。

I've tried to use almost all date formatting options for the column but without any luck. 我已经尝试为该列使用几乎所有日期格式化选项,但是没有任何运气。

I would rather not change the csv manually. 我宁愿不手动更改csv。

Can anyone help me with this? 谁能帮我这个?

I almost always import data into a staging table where all the columns are strings. 我几乎总是将数据导入到所有表都是字符串的登台表中。

Then I use queries to load the final table. 然后,我使用查询来加载最终表。

This has several advantages: 这有几个优点:

  • It gives me much more control over how the data is transformed. 它使我可以更好地控制数据的转换方式。
  • It makes it easier to debug problems -- the entire staging table can be queried to find all rows with a particular issue (for instance). 它使调试问题变得更加容易-可以查询整个登台表以查找具有特定问题的所有行(例如)。
  • Additional validations can be performed before loading into the final table. 在加载到最终表之前,可以执行其他验证。

This is just a suggestion, but you might find that overall this takes less time. 这只是一个建议,但您可能会发现总体而言,此过程花费的时间更少。

The DateStyle setting is probably set to MDY. DateStyle设置可能设置为MDY。 You can check this by running: 您可以通过运行以下命令进行检查:

show datestyle;

Although dd.mm.yyy isn't listed as a standard input format, if you expect it to work, you will need the DateStyle to line up with the ordering here (DMY). 尽管dd.mm.yyy并未列为标准输入格式,但如果您希望它可以工作,则将需要DateStyle与此处的顺序(DMY)保持一致。

The date/time style can be selected by the user using the SET datestyle command, the DateStyle parameter in the postgresql.conf configuration file, or the PGDATESTYLE environment variable on the server or client. 用户可以使用SET datestyle命令,postgresql.conf配置文件中的DateStyle参数或服务器或客户端上的PGDATESTYLE环境变量来选择日期/时间样式。

See section "Date Order Conventions": 请参阅“日期顺序约定”部分:

https://www.postgresql.org/docs/current/static/datatype-datetime.html https://www.postgresql.org/docs/current/static/datatype-datetime.html

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

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