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';
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.
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.
Add an element to a set using the UPDATE command and the addition (+) operator. cqlsh> UPDATE cycling.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With