Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra CQL - Update command to not create new row

Tags:

cassandra

cql

Is there any way to prevent the CQL command Update from creating a new row if the row key 'row1' doesn't exist?

UPDATE columnfamily SET data = 'test data' WHERE key = 'row1';
like image 775
mesh Avatar asked Mar 14 '12 20:03

mesh


People also ask

Is insert and update same in Cassandra?

Insert, Update, and Upsert Because Cassandra uses an append model, there is no fundamental difference between the insert and update operations. If you insert a row that has the same primary key as an existing row, the row is replaced. If you update a row and the primary key does not exist, Cassandra creates it.

How does update work in Cassandra?

UPDATE writes one or more column values to a row in a Cassandra table. Like INSERT, UPDATE is an upsert operation: if the specified row does not exist, the command creates it. All UPDATEs within the same partition key are applied atomically and in isolation.

How do you update sets in Cassandra?

Add an element to a set using the UPDATE command and the addition (+) operator. cqlsh> UPDATE cycling.

What is Upsert in Cassandra?

Upsert means that Cassandra will insert a row if a primary key does not exist already otherwise if primary key already exists, it will update that row.


1 Answers

Update 2015-04-10:

As of Cassandra 2.0 you can use light weight transactions to accomplish this. Be aware that although they are called "light weight" these queries require a lot more work to be done on the Cassandra cluster.

Thanks to @BSB for the update.

Pre 2.0 answer:

No. Unlike in SQL, in CQL Update and insert are semantically the same. You would have to do a read first to determine the existence of the row.

like image 70
psanford Avatar answered Sep 30 '22 06:09

psanford