Overriding write timestamps

Typically, write timestamps are assigned to data automatically by Cassandra, reflecting the time at which the cluster initially receives the request. However, CQL gives us a mechanism to override the default timestamp and instead choose our own.

To demonstrate, let's say we want to add a location value to the bob user record at a specific timestamp: December 14, 2016 at 10.33.24 UTC. In order to do this, we can use the USING TIMESTAMP clause in our UPDATE query:

UPDATE "users" USING TIMESTAMP 1481711604904000 SET "location" = 'Austin, TX' WHERE "username" = 'bob';

Reading bob's user record back, we can see that it now has the location we specified:

Now let's issue another update to bob's location using a TIMESTAMP ...

Get Learning Apache Cassandra - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.