Cassandra: Unable to coerce '2016-04-06 13:06:11.534000' to a formatted date (long)

farhawa picture farhawa · Apr 6, 2016 · Viewed 11.2k times · Source

I am trying to UPDATE an existing item in my cassandra DB using cqlsh:

$ > UPDATE allEvents SET "isLastEvent" = True WHERE "websiteId" = 'sd-8231'
AND "purchaser" = False
AND "currentTime" = '2016-04-06 13:06:11.534000';

And I got this:

InvalidRequest: code=2200 [Invalid query] message="Unable to coerce '2016-04-06 13:06:11.534000' to a formatted date (long)"

In case it can help:

$ > show version
[cqlsh 5.0.1 | Cassandra 3.0.2 | CQL spec 3.3.1 | Native protocol v4]

Answer

Aaron picture Aaron · Apr 6, 2016

That's because Cassandra timestamp types only support milliseconds. Your currentTime has too much precision. Trim off the last three zeros, and that should work:

UPDATE allEvents SET "isLastEvent" = True 
WHERE "websiteId" = 'sd-8231'
      AND "purchaser" = False 
      AND "currentTime" = '2016-04-06 13:06:11.534';