CREATE TABLE IF NOT EXISTS my_counters (
partition_key text,
clustering_key text,
count counter,
PRIMARY KEY ((partition_key), clustering_key)
);
我现在想在两个聚类键下增加计数器。 根据更新规范,这应该是可能的: http://docs.datastax.com/en/cql/3.1/cql/cql_reference/update_r.html
但我得到“无效的操作符IN for PRIMARY KEY ...”错误
UPDATE my_counters SET count = count + 1 WHERE partition_key = ? AND clustering_key IN (?, ?)
这是计数器的特定限制吗?我知道我可以使用每个查询使用一个聚类键来编写一个计数器批处理,但我宁愿不这样做。
答案 0 :(得分:2)
来自http://docs.datastax.com/en/cql/3.3/cql/cql_reference/update_r.html 只有分区键的最后一列支持IN关系。
如果没有指定完整的PRIMARY KEY(分区键+聚类键),也无法进行更新
create table spending_by_country_state (country text,state text,amount int, primary key ((country,state)));
select * from spending_by_country_state;
country | state | amount
---------+-----------+--------
India | Karnataka | 20000
India | Kerala | 10000
cqlsh:test> update spending_by_country_state set amount = 10001 where country = 'India' and state in ('Karnataka','Kerala');
cqlsh:test> select * from spending_by_country_state;
country | state | amount
---------+-----------+--------
India | Karnataka | 10001
India | Kerala | 10001
(2 rows)