【问题标题】:Is it possible to use a timestamp in ms since epoch in select statement for Cassandra?是否可以在 Cassandra 的 select 语句中使用自纪元以来的 ms 时间戳?
【发布时间】:2015-09-05 19:45:27
【问题描述】:

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

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

谢谢!

【问题讨论】:

  • 您在失败的“尝试这样做”中看到了什么?

标签: cassandra timestamp cql


【解决方案1】:

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

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    • 2012-08-05
    • 1970-01-01
    • 2019-12-04
    • 2013-03-26
    • 2013-08-19
    • 1970-01-01
    相关资源
    最近更新 更多