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

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

我正在尝试将 .csv 添加到数据库中的 table。

.csv 中的所有日期均采用此格式 dd.mm.yyyy ( 18.10.2017)。

我正在通过 pgadmin 导入,但总是收到无效输入错误。

我已尝试使用该列的几乎所有日期格式设置选项,但都没有成功。

我不想手动更改 csv。

谁能帮我解决这个问题?

我几乎总是将数据导入暂存 table,其中所有列都是字符串。

然后我使用查询加载最终的table。

这有几个优点:

  • 它使我能够更好地控制数据的转换方式。
  • 它使调试问题变得更容易 -- 可以查询整个暂存 table 以查找具有特定问题的所有行(例如)。
  • 可以在加载到最终 table 之前执行其他验证。

这只是一个建议,但您可能会发现总体而言,这花费的时间更少。

DateStyle 设置可能设置为 MDY。您可以通过 运行:

检查
show datestyle;

尽管 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.

参见第 "Date Order Conventions" 部分:

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