Updating a column in Kassandra based on Where clause

I have a very simple table

cqlsh:hell> describe columnfamily info ;

CREATE TABLE info (
  nos int,
  value map<text, text>,
  PRIMARY KEY (nos)
) 

The following is a query in which I am trying to update a value.

update info set value = {'count' : '0' , 'onget' :  'function onget(value,count) { count++ ; return {"value": value, "count":count} ; }' } where nos  <= 1000 ;
Bad Request: Invalid operator LTE for PRIMARY KEY part nos

I use any operator to indicate a restriction. He complains about an invalid operator. I'm not sure what I'm doing wrong here, according to the cassandra 3.0 cql document, there are similar update requests.

Below is my version

[cqlsh 4.1.0 | Cassandra 2.0.3 | CQL spec 3.1.1 | Thrift protocol 19.38.0]

I have no idea what is going wrong.

+4
source share
3 answers

The answer is indeed in my comment, but it needs to be developed. To reformulate the comment ...

where . , - , == .

Cassandra . CQL , . nos. , , . , - , , . , , . , . , .

+7

Cassandra , .

update info set value = {'count' : '0' , 'onget' :  'function onget(value,count) { count++ ; return {"value": value, "count":count} ; }' } where nos  <= 1000 ;

-, onget ? , nos < 1000. .

nos, int. , map -, .

Also, you probably don't want to have a noscolumn that changes the value as the primary key.

CREATE TABLE info (
  id UUID,
  value map<text, text>,
  PRIMARY KEY (id)
) 

CREATE TABLE nos_counter (
  info_id UUID,
  nos COUNTER,
  PRIMARY KEY (info_id)
) 

Now you can update the nos counter like this.

update info set nos = nos + 1 where info_id = 'SOME_UUID';
-1
source

Source: https://habr.com/ru/post/1537046/


All Articles