Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how UPDATE rows in cassandra using only Partition Key?

My table looks like this

create table Notes(
    user_id varchar,
    real_time timestamp,
    insertion_time timeuuid,
    read boolean PRIMARY KEY (user_id,real_time,insertion_time)
);

create index read_index on Notes (read);

I want update all the rows with user_id = 'xxx' without having to specify all the clustering indexes.

UPDATE Notes SET read = true where user_id = 'xxx'; // Says Error

Error: message="Missing mandatory PRIMARY KEY part real_time

I have tried creating a secondary index, but its not allowed on the primary key.

How can i solve this?

I chose user_id to be in the primary key cause i want to be able to do select * from Notes where user_id = 'xxx' should be possible.

like image 397
mehnaazm Avatar asked Dec 04 '14 13:12

mehnaazm


People also ask

How do you update a partition key column in Cassandra?

In utility "DataStax Dev Center", select table and use command "Export All result to file as INSERT". It will save all data from table to file with Insert CQL-instructions. Then you should drop table, create new one with new PARTITION KEY and finally fill it by instructions from file via CQL.

How do you update a row in Cassandra?

Update a row in a table with a complex primary key: To do this, specify all keys in a table having compound and clustering columns. For example, update the value of a column in a table having a compound primary key, userid and url: UPDATE excelsior.

Can you update primary key in Cassandra?

In Cassandra, primary keys are immutable so an update that changes a primary key must be treated as a delete and an insert.


1 Answers

While this might be possible with a RDBMS and SQL, it is not possible with cql in Cassandra. From the DataStax documentation on the UPDATE command:

Each update statement requires a precise set of primary keys to be specified using a WHERE clause. You need to specify all keys in a table having compound and clustering columns.

You'll probably need to write something quick in Python (or one of the other drivers) to perform this type of update.

like image 176
Aaron Avatar answered Oct 21 '22 05:10

Aaron