示例代码:
show timezone;
TimeZone
---------------
Europe/Berlin
(1 row)
create table foo (ts timestamp without time zone);
insert into foo values ('2023-10-28 23:58:00');
insert into foo values ('2023-10-29 00:58:00');
insert into foo values ('2023-10-29 01:58:00');
select (ts at time zone 'utc' at time zone 'Europe/Berlin')::timestamptz as x from foo order by x;
x
------------------------
2023-10-29 01:58:00+02
2023-10-29 02:58:00+01 <<<<------
2023-10-29 02:58:00+01
(3 rows)
如果标记线不是
2023-10-29 02:58:00+02
?
我的理解是,欧洲/柏林的时钟在凌晨 3 点倒退,因此UTC '2023-10-29 00:58:00'
应该对应于时钟倒退02:58:00
之前,因此仍然是 +02,或者如果您愿意的话,也可以是 CEST。我错了吗?
这
at time zone 'Europe/Berlin'
会导致偏移量丢失。(运行该查询并查看)。然后,当您返回到 timestamptz 时,它没有关于选择要重新添加的偏移量的信息。没有办法从一开始就记住它最初有什么偏移量。