业务场景
使用dbeaver工具,执行按时间(Datetime类型)条件查询数据
异常日志
yaml
SQL 错误 [53] [07000]: Code: 53, e.displayText() = DB::Exception: Cannot convert string 2024-01-30 07:01:32.000 to type DateTime: while executing 'FUNCTION equals(time : 0, '2024-01-30 07:01:32.000' : 29) -> equals(time, '2024-01-30 07:01:32.000') UInt8 : 30' (version 21.7.3.14 (official build))
, server ClickHouseNode [uri=http://36.134.39.183:18123/default, options={use_server_time_zone=false,use_time_zone=false}]@1582988255
解决办法
使用toDateTime 方法对时间进行转换
toDateTime(time, 'Asia/Shanghai'),转成东八区的时间
sql
SELECT count(1) from uTableName u WHERE toDateTime(time, 'Asia/Shanghai') > '2024-01-31 00:00:00';
DELETE from uTableName WHERE toDateTime(time, 'Asia/Shanghai') > '2024-01-31 00:00:00';
SELECT count(1) from cTableName c WHERE toDateTime(time, 'Asia/Shanghai') > '2024-01-31 00:00:00';
DELETE from cTableName WHERE toDateTime(time, 'Asia/Shanghai') > '2024-01-31 00:00:00';