如何更新cassandra中的timeuuid列

How to update timeuuid column in cassandra

如何更新 Cassandra 中的 timeuuid 列?

我尝试了以下查询

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

失败并显示消息

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

所以我尝试将常量值转换为 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);

这次失败并报错

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

我看到了有关转换函数的文档,timeuuid 未在任何其他类型的输出类型下列出。

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

这是否意味着 timeuuid 列一旦创建就无法更新?

更新: 我在上面的页面上看到了以下信息

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.

因此,可以更新 timeuuid 列。 mycolumn 不是主键的一部分。

更新二:

即使是以下命令也会失败并出现相同的错误no viable alternative at input

UPDATE website SET api_key = api_key WHERE 1;

那么我做错了什么?

我在 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.

没有必要引用uuid