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

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

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, HANA, HSQLDB, INFORMIX, ORACLE, 
-- POSTGRES, REDSHIFT, SNOWFLAKE, SQLDATAWAREHOUSE, SQLITE, SYBASE, TERADATA, TRINO, VERTICA, YUGABYTEDB
CASE
  WHEN 1 = 2 THEN 3
  ELSE 4
END

-- AURORA_MYSQL, MARIADB, MEMSQL, MYSQL
if(1 = 2, 3, 4)

(These are currently generated with jOOQ 3.19, 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