2015-10-05 70 views
2

我有以下的CQL3表。CQL3(Cassandra)upsert增加一個計數器

CREATE TABLE UserKarma (
    user_id uuid, 
    sub_type text, 
    karma counter, 
    PRIMARY KEY(user_id, sub_type) 
) WITH COMPACT STORAGE 

如何插入或更新(單個查詢)值並增加計數器?如果條目不存在,由於默認情況下該計數器爲0,則使用此upsert創建的所有新記錄應爲1

回答

2

我想通了。

UPDATE UserKarma SET karma = karma + 1 where user_id = d9d9354a-32e9-46d7-a56c61e21b486ae3 and sub_type = 'test';