为什么我的Cassandra更新不起作用?

jcm*_*jcm 6 cassandra

我有以下Cassandra表:

create table start_stop (id text, start text, end text, price double, PRIMARY KEY (id, start));

我做这样的插入:

insert into start_stop (id, start) values ('123', 'w');

现在我想做一个更新:

update start_stop set end = 'z' where id = '123';

我收到一个错误: InvalidRequest: code=2200 [Invalid query] message="Some clustering keys are missing: start"

除了在执行更新之前执行查询以查找起始值之外,我该如何解决这个问题?

Abh*_*and 7

您的主键不完整,cassandra只能在主键匹配时更新行.

如果你看一下你的表结构,(id,start)combined会生成主键,其中id是分区键.

在cassandra中,更新和插入之间没有区别,但在任何一种情况下,您都需要拥有完整的主键,以便cassandra找到特定的行.

您需要使用以下任一更新.

update start_stop set end = 'z' where id = '123' and start='w';

insert into start_stop (id, start, end) values ('123', 'w', 'z');
Run Code Online (Sandbox Code Playgroud)