0

给定一张桌子:

CREATE TABLE t (
    k text,
    v1 int,
    v2 int,
    PRIMARY KEY (k)
)

是否可以通过单个查询设置v1为某个值并删除(设置为 null) ?v2就像是:

UPDATE t SET v1=100, v2=NULL WHERE k='somekey';

我浏览了文档,但一无所获。

拥有功能会很好,原因有两个:

  • 使用准备好的语句更新包含大量列的表现在真的很痛苦。
  • 如果我的理解是正确的,单个查询的行更新应该是原子的,而不能保证两个后续查询。
4

2 回答 2

3

您建议的查询(至少)在 CQL3 中有效:

cqlsh:ks> UPDATE t SET v1=100, v2=NULL WHERE k='somekey';
cqlsh:ks> select * from t;

 k       | v1  | v2
---------+-----+------
 somekey | 100 | null

如果您想进行更复杂的原子更新,例如跨不同的行键或列族,您可以将单独的 UPDATE 包装在BEGIN BATCH...中APPLY BATCH

于 2013-07-24T19:47:31.493 回答
0

Alternatively to updating to null, you might consider using the DELETE operation if you just want to remove data, which works atomically on columns and/or rows.

You mentioned you could not find the documentation. Here is the documentation related to Richard's excellent answer: - Updates on a single row by a single query are atomic by default. - Batch operations are also atomic since 1.2

于 2013-07-25T09:10:44.487 回答