简体   繁体   中英

How to update a column value in Cassandra Using CQL?

I have created a keyspace with two column fields. One is Id and another one is name. I have inserted records in that keyspace. I want to update the name filed of a particular id.

I have used the following CQL query

UPDATE keyspaceName/columnFalmilyName SET name='name' WHERE id = 'id' 

While Executing this query it throws the Exception of

InvalidRequestException(why:line 1:56 mismatched input 'id' expecting K_KEY)...

If the query framed is wrong means, how to update the record using CQL?

Inserts and updates require specifying the row key, whereas you seem to be trying to use a column name. What key have you used when inserting new id,name pairs?

Refer to the CQL documentation on [http://cassandra.apache.org/doc/cql3/CQL.html][1]

<update-stmt> ::= UPDATE <tablename>
                  ( USING <option> ( AND <option> )* )?
                  SET <assignment> ( ',' <assignment> )*
                  WHERE <where-clause>
The UPDATE statement writes one or more columns for a given row in a table. The 
<where-clause> is used to select the row to update and must include all columns 
composing the PRIMARY KEY. Other columns values are specified through <assignment> 
after the SET keyword.

You need to take a look at your ColumnFamily definition and see what your primary key is.

你试过吗:UPDATE keyspaceName/columnFalmilyName SET name='name' WHERE id = (without '')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM