# What is the order of returned columns in a failed IF expression in YCQL

**URL:** <https://forum.yugabyte.com/t/what-is-the-order-of-returned-columns-in-a-failed-if-expression-in-ycql/924>\
**Category:** General\
**Created:** [January 12, 2021, 5:14pm UTC](https://forum.yugabyte.com/t/what-is-the-order-of-returned-columns-in-a-failed-if-expression-in-ycql/924 "2021-01-12T17:14:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dorian\_yugabyte](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/dorian_yugabyte/32/206_2.png) [@dorian\_yugabyte](https://forum.yugabyte.com/u/dorian_yugabyte)\
**Post date:** [January 12, 2021, 5:14pm UTC](https://forum.yugabyte.com/t/what-is-the-order-of-returned-columns-in-a-failed-if-expression-in-ycql/924/1 "2021-01-12T17:14:51Z")

</div>

[Question posted by a user on [YugabyteDB Community Slack](https://www.yugabyte.com/slack) ]

I am trying to perform Light weight transaction using `update` statement. Is there any guarantee on the order of columns returned if the `IF expression` is failed. Below is my table model & the query I’m trying to attempt:

```auto
$ create table test.sample (ip inet, hr int, source text, source_id text, g map<int, int>, b map<int, int>, r map<int, int>, c map<int, blob>, primary key(ip, hr, source, source_id));
$ insert into sample(ip, hr, source, source_id, g, b, r, c) values('1.2.3.4',456, 'alpha', 'a',{0:1},{1:2},{2:1},{0:0x12});
$ update sample set g[1]=10 where ip='1.2.3.4' and hr=456 and source='alpha' and source_id='a' if g[0]=1 and b[1]=3;
 [applied] | ip | hr | source | source_id | b | g
-----------+---------+-----+--------+-----------+--------+--------
     False | 1.2.3.4 | 456 | alpha | a | {1: 2} | {0: 1}
$ update sample set g[1]=10 where ip='1.2.3.4' and hr=456 and source='alpha' and source_id='a' if g[0]=1 and b[1]=3 and r[0]=2 and c[0]=0xaf;;
 [applied] | ip | hr | source | source_id | c | r | b | g
-----------+---------+-----+--------+-----------+-----------+--------+--------+--------
     False | 1.2.3.4 | 456 | alpha | a | {0: 0x12} | {2: 1} | {1: 2} | {0: 1}

```

1. how to determine the order of columns returned, such that I can utilize them for retry?
2. what is the logic in deciding which columns should be returned for a `failed` LWT statement? Is it amalgamation of (where & IF expressions)

---

<div class="post-metadata">

**Author:** ![dorian\_yugabyte](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/dorian_yugabyte/32/206_2.png) [@dorian\_yugabyte](https://forum.yugabyte.com/u/dorian_yugabyte)\
**Post date:** [January 12, 2021, 5:15pm UTC](https://forum.yugabyte.com/t/what-is-the-order-of-returned-columns-in-a-failed-if-expression-in-ycql/924/2 "2021-01-12T17:15:30Z")

</div>

The order will be primary key columns (in the order from the primary key declaration) first, then static columns (if any), and then regular (non-key, non-static) columns.

I don’t think we define an order _within_ the static columns and regular columns groups. However, the result is a proper (Y)CQL result set containing the metadata too (e.g. column names/types, etc). So, if possible, I’d recommend using those so that you don’t rely on the order itself.

The exact code snippet would depend on the driver/API you are using but for instance in the `Row` class of the Java driver there are, for each type, functions to get the value by index (e.g. `row.getInt(2)` ) or by name (e.g. `row.getInt("hr")` ).

See some examples in our code (tests) in: [TestConditionalDml.java#L74](https://github.com/yugabyte/yugabyte-db/blob/master/java/yb-cql/src/test/java/org/yb/cql/TestConditionalDml.java#L74)2. That’s correct, the result set for a failed conditional DML statement will contain exactly the set of columns referenced in the `WHERE` or `IF` clause.

[credit @mihnea]
