UPDATE是否成为隐含的​​INSERT

编程入门 行业动态 更新时间:2024-10-26 18:19:05
本文介绍了UPDATE是否成为隐含的​​INSERT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

对于Cassandra,如果所选行不存在, UPDATE 是否会隐含地成为 INSERT ?也就是说,如果我说

For Cassandra, do UPDATEs become an implied INSERT if the selected row does not exist? That is, if I say

UPDATE users SET name = "Raedwald" WHERE id = 545127

和 id 是 PRIMARY KEY ,并且该表没有键为545127的行,将等同于

and id is the PRIMARY KEY of the users table, and the table has no row with a key of 545127, will that be equivalent to

INSERT INTO users (id, name) VALUES (545127, "Raedwald")

我知道情况正好相反:对于已经存在的 id 的 INSERT 具有该 id 的行的 UPDATE 。出于这个原因,较早的Cassandra文档讨论了插入实际上是 upserts。

I know that the opposite is true: an INSERT for an id that already exists becomes an UPDATE of the row with that id. Older Cassandra documentation talked about inserts actually being "upserts" for that reason.

我对CQL3(Cassandra版本1.2+)感兴趣。

I'm interested in the case for CQL3, Cassandra version 1.2+.

推荐答案

是的,对于Cassandra UPDATE 是 INSERT的同义词,如 CQL文档中所述它说以下有关 UPDATE 的信息:

Yes, for Cassandra UPDATE is synonymous with INSERT, as explained in the CQL documentation where it says the following about UPDATE:

请注意,与SQL不同, UPDATE 不检查该行的先前存在性:如果该行之前不存在,则创建该行,否则进行更新。此外,没有办法知道是哪个创建或更新发生的。实际上, INSERT 和 UPDATE 的语义是相同的。

Note that unlike in SQL, UPDATE does not check the prior existence of the row: the row is created if none existed before, and updated otherwise. Furthermore, there is no mean to know which of creation or update happened. In fact, the semantic of INSERT and UPDATE are identical.

要使语义有所不同,Cassandra需要进行读取才能知道该行是否已存在。 Cassandra经过写优化,因此您可以始终假定它在执行任何写操作之前都不会进行读操作。唯一的例外是计数器(除非 replicate_on_write = false ),在这种情况下,增量复制涉及读取。

For the semantics to be different, Cassandra would need to do a read to know if the row already exists. Cassandra is write optimized, so you can always assume it doesn't do a read before write on any write operation. The only exception is counters (unlessreplicate_on_write = false), in which case replication on increment involves a read.

更多推荐

UPDATE是否成为隐含的​​INSERT

本文发布于:2023-10-20 03:37:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1509728.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UPDATE   INSERT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!