问题
In SQL, I am able to do:
select getdate(), getdate() - 7
Which returns the current date as well as current date - 7 days. I want to achieve the same in Cassandra CQL. I tried:
select dateof(now())
But that does not work. It works only on insert and not in select. How can I get the same? Any help would be appreciated.
回答1:
select dateof(now())
On its own, you are correct, that does not work. But if you have a table that you know only has one row (like system.local
):
aploetz@cqlsh:stackoverflow> SELECT dateof(now()) FROM system.local ;
dateof(now())
--------------------------
2015-03-26 03:18:39-0500
(1 rows)
Unfortunately, Cassandra CQL does not (yet? CASSANDRA-5505) include support for arithmetic operations, let alone date arithmetic. So subtracting 7 days from that value is something that you would have to do in your application level.
来源:https://stackoverflow.com/questions/29272691/get-current-date-in-cassandra-cql-select