Search code examples
cassandraprimary-keyinsert-updatecomposite-primary-key

Updating values in cluster key in cassandra


I have a schema :

id, target , value

with id=primary key, target=cluster key

Now, I wish to update some values in target depending on id. Is this possible?


Solution

  • While you haven't provided much context, in Cassandra you can never update columns that are in the primary key (either in the partition side or in the clustering one).

    The only way to achieve something equivalent is to delete the row you want to update a column in and then reinsert it with the updated value. This however should not really be done as a standard operation. ( I have used this when data needed to be updated in production due to user or application mistakes but I never designed the application to use this pattern). There is however another problem, doing this often enough you will start having problems with the tombstones not to mention the overhead if the row you "update" is a wide row.

    My advice is, avoid having to update a clustering column, try and achieve the unicity some other way and move the updatable column to the regular ones. If you needed that column however for the filtering capabilities then things get harder.
    Cheers.