Available in versions: Dev (3.20) | Latest (3.19) | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11

IIF

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The IIF() function checks if the first argument is TRUE to produce the second argument, or the third argument otherwise. It works in a similar way as the NVL2 function or the CASE expression

SELECT
  iif(1 = 1, 3, 4),
  iif(1 = 2, 3, 4);
create.select(
  iif(inline(1).eq(inline(1)), inline(3), inline(4))
  iif(inline(1).eq(inline(2)), inline(3), inline(4))).fetch();

The result being

+-----+-----+
| iif | iif |
+-----+-----+
|   3 |   4 |
+-----+-----+

Dialect support

This example using jOOQ:

iif(inline(1).eq(inline(2)), inline(3), inline(4))

Translates to the following dialect specific expressions:

Access, SQLServer

iif(1 = 2, 3, 4)

ASE, Aurora Postgres, BigQuery, CockroachDB, DB2, Derby, DuckDB, Exasol, Firebird, H2, HSQLDB, Hana, Informix, Oracle, Postgres, Redshift, SQLDataWarehouse, SQLite, Snowflake, Sybase, Teradata, Trino, Vertica, YugabyteDB

CASE
  WHEN 1 = 2 THEN 3
  ELSE 4
END

Aurora MySQL, ClickHouse, MariaDB, MemSQL, MySQL

if(1 = 2, 3, 4)

(These are currently generated with jOOQ 3.20, see #10141), or translate your own on our website

References to this page

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo