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
但我得到"无效的操作符在主键…"错误
UPDATE my_counters SET count = count + 1 WHERE partition_key = ? AND clustering_key IN (?, ?)
这是计数器的特定限制吗?我知道我可以在每个查询中使用一个集群键来编写计数器批处理,但我宁愿不这样做。
From http://docs.datastax.com/en/cql/3.3/cql/cql_reference/update_r.htmlIN关系只支持分区键的最后一列
如果没有指定完整的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)