Search code examples
cassandratimeuuid

Update rows with timeuuid as clustering column


I've a table which has a String as key and a timeuuid as clustering column.

What I'd like to do is, to do an update on it based on timeuuid < now().

Example:

UPDATE table SET is_used = true WHERE key1 = 'value' AND created_at < timeuuid('2016-02-03') IF is_used != true;

But getting

InvalidRequest: code=2200 [Invalid query] message="Invalid operator < for PRIMARY KEY part created_at

Is there any workaround or solution for that? Why is the clustering column considered as primary key in this case?

All the best

---- Update1: ---

I am using cassandra version 2.2 the schema is the following:

CREATE TABLE book (
created_at timeuuid,
book_type varchar,
book_title varchar
PRIMARY KEY ((book_type), created_at)) WITH CLUSTERING ORDER BY (book created_at DESC);

Solution

  • Unfortunately it doesn't look like you can do UPDATEs where the clustering column is restricted on a range, even in the C* 3.5.

    From what I can tell you have to specify the whole primary key when doing an UPDATE it cannot be applied to a range of data.

    As you are doing a conditional update anyways, you could do a SELECT first to identify candidate rows to change, and then do the updates in a batch (since they all apply to the same partition this is ok).