Billy Jacobson
Billy Jacobson

Reputation: 1703

Inserting date using yesterday/tomorrow into Cassandra

I'm trying to insert a date into Cassandra based on the current date.

create table mobileTimeSeries (
deviceid text,
date date,
PRIMARY KEY(deviceid, date));

insert into mobileTimeSeries (deviceid, date) values ('test', toDate(now()));

That works, but I'm wondering if it's possible to do something like

insert into mobileTimeSeries (deviceid, date) values ('test', toDate(now()-1));
insert into mobileTimeSeries (deviceid, date) values ('test', toDate(now()+1));

I just get this error mismatched input '+' expecting ')' (... 'tablet',toDate(now()) [+]...)

Not sure if this is possible at all. Thanks

Upvotes: 0

Views: 729

Answers (1)

Chris Lohfink
Chris Lohfink

Reputation: 16430

You can calculate date on your app and just insert it as a date instead of using now().

After CASSANDRA-11936 in 4.0+ you can do now() - 1d kinda things.

Upvotes: 1

Related Questions