【问题标题】:"Invalid operator IN for PRIMARY KEY" when updating multiple clustering columns using IN clause使用 IN 子句更新多个集群列时出现“主键的无效运算符 IN”
【发布时间】:2016-01-06 17:54:23
【问题描述】:
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...”错误

UPDATE my_counters SET count = count + 1 WHERE partition_key = ? AND clustering_key IN (?, ?)

这是计数器的特定限制吗?我知道我可以为每个查询使用一个聚类键编写一个计数器批处理,但我不想这样做。

【问题讨论】:

    标签: cassandra cql cql3


    【解决方案1】:

    来自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)
    

    【讨论】:

    • 是的,我错过了“分区键的最后一列”这一点。不确定不支持使用 IN 更新一组集群键的原因是什么。 SELECT 与 CK 的 IN 一起工作正常。关于您的第二点,我确实指定了所有键。
    猜你喜欢
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    • 2020-10-19
    • 2015-12-28
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多