Cassandra - 我如何比较时间戳?

时间:2016-07-07 08:39:15

标签: date cassandra timestamp

我有这张桌子:

CREATE TABLE mytablename (
  name text,
  typeid int,
  activefrom timestamp,
  status text,
  PRIMARY KEY ((name), typeid, activefrom)
)

我想查询一系列时间戳activefrom,例如这里有一些查询:

  • activefrom> ' 2000年1月2日'
  • activefrom> ' 2000年1月2日' AND activefrom< ' 2010-01-02'

我注意到它不像在sql中那样工作。

例如

 name | typeid | activefrom               | status
 ------+--------+--------------------------+--------------
  dani |  99999 | 1970-01-26 00:00:00+0000 | OK
  dani |  99999 | 1970-01-26 01:00:00+0000 | OK
  dani |  99999 | 2070-01-26 00:00:00+0000 | OK
  dani |  99999 | 1970-01-01 00:00:00+0000 | OK

查询:

  select * from mytablename where name='dani' and typeid=99999 and activefrom > '2070-01-02 12:51:58+0000';

我的结果是:

  dani |  99999 | 2070-01-26 00:00:00+0000 | OK
  dani |  99999 | 1970-01-01 00:00:00+0000 | OK

Cassandra版本:

  cqlsh 4.1.1 | Cassandra 2.1.13.1218 | CQL spec 3.1.1 | Thrift protocol 19.39.0

有什么建议吗? 谢谢

1 个答案:

答案 0 :(得分:0)

我试过了,这就是我得到的。

cqlsh:test> CREATE TABLE mytablename (
    ...   name text,
    ...   typeid int,
    ...   activefrom timestamp,
    ...   status text,
    ...   PRIMARY KEY ((name), typeid, activefrom)
    ... )
    ... ;

cqlsh:test> insert into mytablename (name,typeid,activefrom,status) values ('dani',99999,'1970-01-26 00:00:00+0000','OK');
cqlsh:test> insert into mytablename (name,typeid,activefrom,status) values ('dani',99999,'1970-01-26 01:00:00+0000','OK');
cqlsh:test> insert into mytablename (name,typeid,activefrom,status) values ('dani',99999,'2070-01-26 00:00:00+0000','OK');
cqlsh:test> insert into mytablename (name,typeid,activefrom,status) values ('dani',99999,'1970-01-01 00:00:00+0000','OK');
cqlsh:test> select * from mytablename;

 name | typeid | activefrom                      | status
------+--------+---------------------------------+--------
 dani |  99999 | 1970-01-01 00:00:00.000000+0000 |     OK
 dani |  99999 | 1970-01-26 00:00:00.000000+0000 |     OK
 dani |  99999 | 1970-01-26 01:00:00.000000+0000 |     OK
 dani |  99999 | 2070-01-26 00:00:00.000000+0000 |     OK

(4 rows)
cqlsh:test>   select * from mytablename where name='dani' and typeid=99999 and activefrom > '2070-01-02 12:51:58+0000';

 name | typeid | activefrom                      | status
------+--------+---------------------------------+--------
 dani |  99999 | 2070-01-26 00:00:00.000000+0000 |     OK

(1 rows)
cqlsh:test> 

版本信息:[cqlsh 5.0.1 | Cassandra 3.4-SNAPSHOT | CQL规范3.4.0 |原生协议v4]