Cassandra中的UPDATE和INSERT之间的区别? [英] Difference between UPDATE and INSERT in Cassandra?

查看:1544
本文介绍了Cassandra中的UPDATE和INSERT之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Cassandra执行CQL时, UPDATE INSERT 之间有什么区别?



看起来以前没有什么区别,但现在文档< a>说 INSERT 不支持计数器,而 UPDATE 会。



有没有首选方法使用?

解决方案

Cassandra中的计数器列无法设置为任意值:它们只能通过任意值进行递增或递减。



原因, INSERT 不支持计数器列,因为您不能插入值到计数器列。您只能将 UPDATE (增加或减少)一些值。以下是更新计数器列的方法。

  UPDATE ... SET name1 = name1 +< value> 

您问:



有没有首选方法要使用?或者是否有一个应该在另一个使用?



是的。如果要向数据库插入值,可以使用 INSERT 。如果列不存在,将为您创建。否则, INSERT 的效果类似于 UPDATE 当您没有预先设计的模式(动态列族,即随时插入任何内容)时,INSERT 很有用。如果您之前设计模式(静态列族,类似于RDMS)并且知道每个列,则可以使用 UPDATE


What is the difference between UPDATE and INSERT when executing CQL against Cassandra?

It looks like there used to be no difference, but now the documentation says that INSERT does not support counters while UPDATE does.

Is there a "preferred" method to use? Or are there cases where one should be used over the other?

Thanks so much!

解决方案

Counter Columns in Cassandra couldn't be set to an arbitrary value: they can only be incremented or decremented by any arbitrary value.

For this reason, INSERT doesn't support Counter Column because you cannot "insert" a value into a Counter Column. You can only UPDATE them (increment or decrement) by some value. Here's how you would update a Counter column.

    UPDATE ... SET name1 = name1 + <value> 

You asked:

Is there a "preferred" method to use? Or are there cases where one should be used over the other?

Yes. If you are inserting values to the database, you can use INSERT. If the column doesn't exists, it will be created for you. Otherwise, INSERT's effect is similar to UPDATE. INSERT is useful when you don't have a pre-designed schema (Dynamic Column Family, i.e. insert anything, anytime). If you are designing the schema before hand (Static Column Family, similar to RDMS) and know each column, then you can use UPDATE.

这篇关于Cassandra中的UPDATE和INSERT之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆