1

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);
Brad Schoening
  • 1,281
  • 6
  • 22
questionaire
  • 2,475
  • 2
  • 14
  • 28
  • what version of cassandra are you using? Also, can you share your table schema? This may be possible (range relations on clustering keys) in cassandra 3.x, but can't remember for sure – Andy Tolbert Jun 02 '16 at 14:16

1 Answers1

2

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).

Andy Tolbert
  • 11,418
  • 1
  • 30
  • 45