0

I have this line, how can i reproduce it into CQL? I'm using Amazon Keyspaces which based on Cassandra.

DATEADD(day, @p_daysback, GETDATE());
Alex Ott
  • 80,552
  • 8
  • 87
  • 132
Taifunov
  • 533
  • 1
  • 4
  • 9

1 Answers1

1

Cassandra 4.0 supports date/time arithmetic (added in CASSANDRA-11935), so maybe Amazon Keyspaces support it as well. Basically you either need currentDate() function or cast(now() as date) to get current date, and then add or subtract the given amount of days, like (to get back to 3 days from today):

currentDate() - 3d
Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • Unfortunately this is doesn't work :( currentDate() - this is also doesn't works in KeySpaces, instead of this i'm using toTimeStamp(toDate(now()), but when i'm doing -1d i get an error: mismatched input '-1d' expecting ')' (... toTimeStamp(toDate(now()) [-1]...) This is my query: SELECT * FROM "transaction"."transaction_by_interfaceid" where environment = 'Local' and interfaceid = 1 and organizationid = 1 and starttime <= toTimeStamp(toDate(now()) -1d); – Taifunov Apr 01 '21 at 07:14
  • 1
    then it's a limitation of amazon keyspaces... And UDF may not help you, because, at least in OSS Cassandra, there is no way to use functions in the WHERE – Alex Ott Apr 01 '21 at 07:21