Clickhouse日期时间比较无法正常工作

我正在尝试在Clickhouse中比较日期时间。但似乎它以某种有线方式工作。 我的表格中有一列想要与(now(),'UTC')比较。 如果该列中的datetime值小于我想从该记录中选择数据的时间,则小于(now(),'UTC')时间。

我已经创建了

之类的表

create table my_table (`mytime` DateTime,`data' [type]) ENGINE= engine

我希望队列像 Select data from my_table where mytime < toDateTime(now(),'UTC')

即使mytime> toDateTime(now(),'UTC'),它始终会考虑mytime

deitysix 回答:Clickhouse日期时间比较无法正常工作

在我看来,您插入数据或ClickHouse版本存在错误的方式可能有问题。

以下示例显示了如何以一种在我的19.15.4.10服务器上可以正常工作的方式来尝试尝试做的事情,从而仅选择了较早的行。注意select sleep()以确保now()调用不同。

drop table if exists my_table;
create table my_table (mytime DateTime,data String) engine = Memory;
insert into my_table values(now(),'a');
select sleep(1);
insert into my_table values(toDateTime('2020-01-01 00:00:00','UTC'),'b');
select * from my_table where mytime < now();
select * from my_table where mytime < toDateTime(now(),'UTC');

在我的服务器上,无论选择now()还是对其进行转换都没有关系。我还尝试了您最初定义表的方式,它也可以工作。因此,认为您的数据有问题。

,

此问题背后的原因是在clickhouse中,它将DateTime和DateTime('UTC')当作不同的对象,因此它们之间的比较无法按预期进行。由于我想与(now(),'UTC')进行比较,因此我必须更改 mytimeDateTime ('UTC')

我必须将表更改为

create table my_table (`mytime` DateTime ('UTC'),`data' [type]) ENGINE= engine

本文链接:https://www.f2er.com/3143627.html

大家都在问