# YCQL UPDATE query with IF and IF-NOT-EXISTS expression

**URL:** <https://forum.yugabyte.com/t/ycql-update-query-with-if-and-if-not-exists-expression/1328>\
**Category:** General\
**Created:** [November 25, 2021, 10:19am UTC](https://forum.yugabyte.com/t/ycql-update-query-with-if-and-if-not-exists-expression/1328 "2021-11-25T10:19:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![beatrausch](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/beatrausch/32/322_2.png) [@beatrausch](https://forum.yugabyte.com/u/beatrausch)\
**Post date:** [November 25, 2021, 10:19am UTC](https://forum.yugabyte.com/t/ycql-update-query-with-if-and-if-not-exists-expression/1328/1 "2021-11-25T10:19:55Z")

</div>

Hi,

We have a question regarding the `UPDATE` statement of the YCQL API.  
According to the grammar ([UPDATE statement [YCQL] | YugabyteDB Docs](https://docs.yugabyte.com/latest/api/ycql/dml_update/#diagram)) 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:

```auto
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;

```

---

<div class="post-metadata">

**Author:** ![kannan](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/kannan/32/18_2.png) [@kannan](https://forum.yugabyte.com/u/kannan)\
**Post date:** [November 26, 2021, 12:13am UTC](https://forum.yugabyte.com/t/ycql-update-query-with-if-and-if-not-exists-expression/1328/2 "2021-11-26T00:13:43Z")

</div>

hi @beatrausch

The functionality you are trying is supported. It is just a documentation error. We will get the docs fixed.

If you don’t mind kindly file a docs issue for the same.

regards  
Kannan

---

<div class="post-metadata">

**Author:** ![beatrausch](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/beatrausch/32/322_2.png) [@beatrausch](https://forum.yugabyte.com/u/beatrausch)\
**Post date:** [November 26, 2021, 8:25am UTC](https://forum.yugabyte.com/t/ycql-update-query-with-if-and-if-not-exists-expression/1328/3 "2021-11-26T08:25:14Z")

</div>

Great! I will file an issue.
