Blankman
Blankman

Reputation: 267020

Can I get a lastUpdated column on my tables using triggers?

I want to add a lastUpdated column on my cassandra tables, and have this column autopopulated by cassandra whenever a row is updated.

Does cassandra have triggers that could do this?

The goal is not to have to update code base, just a db migration to make this work.

Upvotes: 0

Views: 53

Answers (1)

Erick Ramirez
Erick Ramirez

Reputation: 16323

Cassandra stores the write time for each column/row/partition. In fact, this is what the coordinators use to determine the latest version of the data and returns it to the clients.

Depending on what you're after, you can use this metadata for your purposes without having to store it separately. There is a built-in function WRITETIME() that returns the timestamp in microseconds for when the data was written (details here).

On the subject of database triggers, they exist in Cassandra but there hasn't been much work done for this functionality for 5 (maybe 7) years so I personally wouldn't recommend their use. I think triggers were always considered experimental and never moved on. In fact, they were deprecated in DataStax Enterprise around 5 years ago. Cheers!

Upvotes: 2

Related Questions