Is it possible to use a timestamp in ms since epoch in select statement for Cassandra?

1.8k Views Asked by At

I know that using the formats listed here (http://docs.datastax.com/en/cql/3.0/cql/cql_reference/timestamp_type_r.html) work to query cassandra. However, I'm having a hard time determining if it is even possible to use ms since epoch in the select statement.

I feel like it should since it data can be sent to cassandra in the ms since epoch (from above: A timestamp type can be entered as an integer for CQL input), but my attempts to do so have failed and I can't find any documentation saying either way.

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, you can use integer timestamps in select statements.

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)