cassandracqltimeuuid

How to update timeuuid column in cassandra


How can I update a timeuuid column in Cassandra?

I tried the following query

cqlsh:mydb> UPDATE mytable SET mycolumn = '99b47d70-b465-11e9-8080-808080808080' WHERE mycolumn= '99a53b30-b465-11e9-8080-808080808080';

and it failed with message

InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid STRING constant (99b47d70-b465-11e9-8080-808080808080) for "mycolumn" of type timeuuid"

So I tried casting the constant values to timeuuid

cqlsh:mydb> UPDATE mytable SET mycolumn = cast('99b47d70-b465-11e9-8080-808080808080' as timeuuid) WHERE mycolumn= cast('99a53b30-b465-11e9-8080-808080808080' as timeuuid);

This time it failed with error

SyntaxException: line 1:34 no viable alternative at input '(' (UPDATE mytable SET mycolumn = cast

I saw the documentation on the cast function, and timeuuid is not listed under the output type for any other type.

https://docs.datastax.com/en/dse/5.1/cql/cql/cql_reference/refCqlFunction.html#refCqlFunction__cast

Does that mean a timeuuid column cannot be updated once created?

Update: I came across the following information on the above page

UPDATE statements SET clause cannot be used to change PRIMARY KEY fields; therefore a new timeuuid can only be set if the target field is not part of the PRIMARY KEY field.

So, it is possible to update timeuuid columns. mycolumn is not part of the PRIMARY key.

Update 2:

Even the following command is failing with the same error no viable alternative at input

UPDATE website SET api_key = api_key WHERE 1;

So what is it that I am doing wrong?


Solution

  • I found the solution at Inserting a hard-coded UUID via CQLsh (Cassandra)

    You shouldn't put the quotes around the UUID to stop it being interpreted as a string i.e.

    There was no need to quote the uuid