短版:是否可以查询与特定日期对应的所有 timeuuid 列?
更多细节:
我有一个定义如下的表:
CREATE TABLE timetest(
key uuid,
activation_time timeuuid,
value text,
PRIMARY KEY(key,activation_time)
);
我已经用单行填充了它,如下(f0532ef0-2a15-11e3-b292-51843b245f21
是与日期对应的 timeuuid 2013-09-30 22:19:06+0100
):
insert into timetest (key, activation_time, value) VALUES (7daecb80-29b0-11e3-92ec-e291eb9d325e, f0532ef0-2a15-11e3-b292-51843b245f21, 'some value');
我可以按如下方式查询该行:
select activation_time,dateof(activation_time) from timetest where key=7daecb80-29b0-11e3-92ec-e291eb9d325e
结果如下(使用cqlsh)
activation_time | dateof(activation_time)
--------------------------------------+--------------------------
f0532ef0-2a15-11e3-b292-51843b245f21 | 2013-09-30 22:19:06+0100
现在让我们假设我的表中有很多数据,我想检索activation_time
与特定日期对应的所有行,比如2013-09-30 22:19:06+0100
.
我本来希望能够查询 和 之间的所有 timeuuid 的范围,minTimeuuid('2013-09-30 22:19:06+0100')
但这maxTimeuuid('2013-09-30 22:19:06+0100')
似乎不可能(以下查询返回零行):
select * from timetest where key=7daecb80-29b0-11e3-92ec-e291eb9d325e and activation_time>minTimeuuid('2013-09-30 22:19:06+0100') and activation_time<=maxTimeuuid('2013-09-30 22:19:06+0100');
看来我需要使用 hack 来增加查询中的第二个日期(增加一秒)来捕获行,即
select * from timetest where key=7daecb80-29b0-11e3-92ec-e291eb9d325e and activation_time>minTimeuuid('2013-09-30 22:19:06+0100') and activation_time<=maxTimeuuid('2013-09-30 22:19:07+0100');
这感觉不对。我错过了什么吗?有没有更清洁的方法来做到这一点?
CQL 文档讨论了timeuuid 函数,但它对带有 timeuuids 的 gte/lte 表达式非常短,除此之外:
min/maxTimeuuid 示例选择 timeuuid 列 t 严格晚于 2013-01-01 00:05+0000 但严格早于 2013-02-02 10:00+0000 的所有行。t >= maxTimeuuid('2013-01-01 00:05+0000') 不会选择恰好在 2013-01-01 00:05+0000 生成的 timeuuid,本质上等同于 t > maxTimeuuid('2013-01 -01 00:05+0000')。
ps 以下查询也返回零行:
select * from timetest where key=7daecb80-29b0-11e3-92ec-e291eb9d325e and activation_time<=maxTimeuuid('2013-09-30 22:19:06+0100');
以下查询返回行:
select * from timetest where key=7daecb80-29b0-11e3-92ec-e291eb9d325e and activation_time>minTimeuuid('2013-09-30 22:19:06+0100');