从 Clickhouse 返回的时间不正确
Incorrect time returned from Clickhouse
我正在观察 ClickHouse 数据库中的 strage 东西
当我在 WHERE 条件中指定日期时间时,陈词滥调将我的请求移动了一个小时。每个具有 DateTime 类型
的表都会发生这种情况
我的机器位于莫斯科时区 UTC+3
服务器位于 CET timezome UTC+1
莫斯科没有夏令时,但问题是前段时间出现的
我认为这是因为欧洲按小时改变时间
例如,给我在23:59和00:19之间的记录
datetime 列具有 DateTime 类型
select datetime from ticker_arch
where
datetime <= '2020-11-23 00:10:00' and
datetime >= '2020-11-22 23:59:00'
order by datetime desc
结果给出了 22:59 和 23:10
之间的记录
2020-11-22 23:09:46
2020-11-22 23:09:46
2020-11-22 23:09:46
2020-11-22 23:09:46
当我 运行 在 Datagrip 和我的代码 DBContext 中查询时会发生这种情况
请推荐
这是 CH JDBC 驱动程序的预期行为。
JDBC 驱动程序将 DateTime 值(为其字符串表示形式)从 CH 服务器时区转换为本地(对于 JVM)时区。
https://github.com/ClickHouse/ClickHouse/issues/17387
CH客户端相同:
# clickhouse-client --use_client_time_zone=1 -q "select now(), toString(now())"
2020-11-25 19:02:31 2020-11-25 20:02:31
# TZ=Europe/Moscow clickhouse-client --use_client_time_zone=1 -q "select now(), toString(now())"
2020-11-25 22:02:59 2020-11-25 20:02:59
now() -- 由客户端使用本地时区呈现为字符串
toString(now()) -- 由服务器使用 servertimezone
呈现为字符串
我正在观察 ClickHouse 数据库中的 strage 东西
当我在 WHERE 条件中指定日期时间时,陈词滥调将我的请求移动了一个小时。每个具有 DateTime 类型
的表都会发生这种情况我的机器位于莫斯科时区 UTC+3 服务器位于 CET timezome UTC+1 莫斯科没有夏令时,但问题是前段时间出现的 我认为这是因为欧洲按小时改变时间
例如,给我在23:59和00:19之间的记录 datetime 列具有 DateTime 类型
select datetime from ticker_arch
where
datetime <= '2020-11-23 00:10:00' and
datetime >= '2020-11-22 23:59:00'
order by datetime desc
结果给出了 22:59 和 23:10
之间的记录2020-11-22 23:09:46
2020-11-22 23:09:46
2020-11-22 23:09:46
2020-11-22 23:09:46
当我 运行 在 Datagrip 和我的代码 DBContext 中查询时会发生这种情况 请推荐
这是 CH JDBC 驱动程序的预期行为。
JDBC 驱动程序将 DateTime 值(为其字符串表示形式)从 CH 服务器时区转换为本地(对于 JVM)时区。
https://github.com/ClickHouse/ClickHouse/issues/17387
CH客户端相同:
# clickhouse-client --use_client_time_zone=1 -q "select now(), toString(now())"
2020-11-25 19:02:31 2020-11-25 20:02:31
# TZ=Europe/Moscow clickhouse-client --use_client_time_zone=1 -q "select now(), toString(now())"
2020-11-25 22:02:59 2020-11-25 20:02:59
now() -- 由客户端使用本地时区呈现为字符串
toString(now()) -- 由服务器使用 servertimezone
呈现为字符串