【发布时间】:2020-07-17 13:48:49
【问题描述】:
我有一个 python 脚本,可以将每小时读数插入到 postgres 数据库中。它在 2010 年 3 月 28 日失败。 postgres 如何将 01:00:00 和 02:00:00 解释为 02:00:00。我做错了什么(ps:适用于在此之前的其他日期)
select to_timestamp('28/03/2010 01:00:00','DD/MM/YYYY HH24:MI:SS');
to_timestamp
------------------------
2010-03-28 02:00:00+01
(1 row)
select to_timestamp('28/03/2010 02:00:00','DD/MM/YYYY HH24:MI:SS');
to_timestamp
------------------------
2010-03-28 02:00:00+01
(1 row)
【问题讨论】:
-
我无法在 postgresql 12 中重现此行为。我建议您将两个选择折叠成一个并检查输出(
select to_timestamp('28/03/2010 01:00:00','DD/MM/YYYY HH24:MI:SS') one, to_timestamp('28/03/2010 02:00:00','DD/MM/YYYY HH24:MI:SS') two, version() v;)。该查询还会告知您正在运行的 postgresql 版本。 -
您的服务器在哪个时区?它可能与 DST 切换有关(尽管这发生在 02:00,而不是在 01:00
标签: sql postgresql date select to-timestamp