"Invalid operator IN for PRIMARY KEY" 使用 IN 子句更新多个集群列时
"Invalid operator IN for PRIMARY KEY" when updating multiple clustering columns using IN clause
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
但我收到 "Invalid operator IN for PRIMARY KEY..." 错误
UPDATE my_counters SET count = count + 1 WHERE partition_key = ? AND clustering_key IN (?, ?)
这是对计数器的特定限制吗?我知道我可以为每个查询使用一个聚类键来编写一个计数器批处理,但我宁愿不这样做。
来自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)
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
但我收到 "Invalid operator IN for PRIMARY KEY..." 错误
UPDATE my_counters SET count = count + 1 WHERE partition_key = ? AND clustering_key IN (?, ?)
这是对计数器的特定限制吗?我知道我可以为每个查询使用一个聚类键来编写一个计数器批处理,但我宁愿不这样做。
来自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)