Search code examples
cassandracqlcassandra-3.0cql3

Cassandra update multiple rows based on condition


I want to update multiple rows in Cassandra if they satisfy my condition with same value(changing flag to false) and my condition field is part of my composite key. But I cannot use whole composite key.


Solution

  • Unfortunately, this is not possible with Cassandra. UPDATEs and INSERTs are all considered write operations. And write operations require a complete PRIMARY KEY.

    Consider this example where I have a partition key of username and a clustering key of transaction_time: PRIMARY KEY (username,transaction_time). If I just try to UPDATE based on username, this fails.

    cassdba@cqlsh:stackoverflow> UPDATE rest_transactions_by_user
           SET http_result = 200 WHERE username='Aaron';
    InvalidRequest: Error from server: code=2200 [Invalid query] 
           message="Some clustering keys are missing: transaction_time"