我创建了一个具有两个列字段的键空间。一个是Id,另一个是名称。我已经在该键空间中插入了记录。我想更新特定ID的名称。
我已经使用以下CQL查询
UPDATE keyspaceName/columnFalmilyName SET name='name' WHERE id = 'id'
在执行此查询时,它将引发Exception
InvalidRequestException(why:line 1:56 mismatched input 'id' expecting K_KEY)...
如果查询框错误,则如何使用CQL更新记录?
最佳答案
插入和更新需要指定行键,而您似乎正在尝试使用列名。插入新的ID,名称对时使用了什么键?
请参阅[http://cassandra.apache.org/doc/cql3/CQL.html][1]上的CQL文档。
<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.
您需要查看ColumnFamily定义,并查看主键是什么。