Hi,
We have a question regarding the UPDATE
statement of the YCQL API.
According to the grammar (UPDATE statement [YCQL] | YugabyteDB Docs) you can use either IF
expressions using columns, or an IF-NOT-EXISTS
expression, but not both in the same query.
When we tried to execute an update query using both type of IF
expressions, it worked.
Could you let us know if we understood the grammar correctly?
If so, is this behavior officially supported?
Reproduce UPDATE
query with IF
expression and IF-NOT-EXISTS
expression:
• yugabyte docker image: yugabytedb/yugabyte:2.8.0.0-b37
• connect to yugabyte using the ycqlsh
• execute the following statements:
CREATE KEYSPACE IF NOT EXISTS ks;
USE ks;
CREATE TABLE IF NOT EXISTS test(key TEXT PRIMARY KEY, value TEXT, checkpoint TEXT);
// as expected the insertion of the row works, because the row does not exist
UPDATE test set value = 'value1', checkpoint = 'cas1' WHERE key = 'key1' IF checkpoint = '' OR NOT EXISTS;
// as expected the update will be applied, because the checkpoint value matches
UPDATE test set value = 'value2', checkpoint = 'cas2' WHERE key = 'key1' IF checkpoint = 'cas1' OR NOT EXISTS;
// as expected the update will not be applied
UPDATE test set value = 'value2', checkpoint = 'cas2' WHERE key = 'key1' IF checkpoint = 'cas1' OR NOT EXISTS;