如何使用CQL更新Cassandra中的列值?

问题描述 投票:1回答:1

我创建了一个包含两个列字段的键空间。一个是Id,另一个是名字。我已在该键空间中插入记录。我想更新特定ID的名称。

我使用了以下CQL查询

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

在执行此查询时,它会抛出异常

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

如果查询框架错误意味着,如何使用CQL更新记录?

java cassandra cql
1个回答
0
投票

插入和更新需要指定行键,而您似乎尝试使用列名。插入新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定义并查看主键是什么。

© www.soinside.com 2019 - 2024. All rights reserved.