1
0
This commit is contained in:
2025-11-03 05:49:10 +08:00
parent bb902c36fc
commit afaa00c056

View File

@@ -1,10 +1,10 @@
-- 设置会话时区 -- 设置会话时区
SET TIME ZONE 'Asia/Shanghai'; SET TIME ZONE 'Asia/Shanghai';
-- msg_time 是 timestamptz类型 -- AT TIME ZONE 在 PostgreSQL 中是重载的,行为取决于左侧的类型
select msg_time from msg where id = 1; -- timestamp WITHOUT time zone AT TIME ZONE zone → 把该 wall time 视为 zone 的本地时间,然后转换为 UTC结果为 timestamptz显示为 UTC 偏移后的时间)。
select msg_time AT TIME ZONE 'Asia/Shanghai' from msg where id = 1; -- timestamptz AT TIME ZONE zone → 把该瞬间转换成 zone 的本地 wall time结果为 timestamp WITHOUT time zone。
select msg_time AT TIME ZONE 'UTC+8' from msg where id = 1; select msg_time at time zone 'Asia/Shanghai' from msg where id = 1;
select msg_time at time zone 'UTC+8' from msg where id = 1;
SELECT to_timestamp(1761850339); select to_timestamp(1761850339) AT TIME ZONE 'Asia/Shanghai';
SELECT to_timestamp(1761850339) AT TIME ZONE 'Asia/Shanghai';