是否可以在 Cassandra 的选择语句中使用自纪元以来的时间戳(以毫秒为单位)



我知道使用这里列出的格式(http://docs.datastax.com/en/cql/3.0/cql/cql_reference/timestamp_type_r.html)可以查询Cassandra。但是,我很难确定是否可以在选择语句中使用自 epoch 以来的 ms。

我觉得应该这样做,因为它的数据可以在 ms 中发送到 cassandra,因为自纪元以来(从上面:时间戳类型可以作为 CQL 输入的整数输入),但我这样做的尝试失败了,我找不到任何文档说这两种方式。

谢谢!

是的,您可以在 select 语句中使用整数时间戳。

cassandra@cqlsh:testkeyspace> CREATE TABLE test (key int, ts timestamp, v int, PRIMARY KEY (key, ts));
cassandra@cqlsh:testkeyspace> INSERT INTO test (key, ts, v) VALUES (0, 1434741481000, 0);
cassandra@cqlsh:testkeyspace> INSERT INTO test (key, ts, v) VALUES (0, 1434741481001, 1);
cassandra@cqlsh:testkeyspace> INSERT INTO test (key, ts, v) VALUES (0, 1434741481002, 2);
cassandra@cqlsh:testkeyspace> SELECT ts, v FROM test WHERE key = 0;
 ts                       | v
--------------------------+---
 2015-06-19 14:18:01-0500 | 0
 2015-06-19 14:18:01-0500 | 1
 2015-06-19 14:18:01-0500 | 2
(3 rows)
cassandra@cqlsh:testkeyspace> SELECT ts, v FROM test WHERE key=0 AND ts >= 1434741481001;
 ts                       | v
--------------------------+---
 2015-06-19 14:18:01-0500 | 1
 2015-06-19 14:18:01-0500 | 2
(2 rows)

最新更新