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.
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.
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.
In Cassandra, primary keys are immutable so an update that changes a primary key must be treated as a delete and an insert.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With