Skip to main content

IIF

Returns a value based upon the evaluation of an input expression.

See also:
[SELECT]


Syntax

SELECT IIF(expression, result_if_true, result_if_false) 
FROM <multipartIdentifier>;

The iif() function is logically equivalent to the CASE expression CASE WHEN expression THEN result_if_true ELSE result_if_false END

Arguments

expression
A boolean expression to be evaluated.

tip

The expression argument can be a nested function such as JSON_EXTRACT.

result_if_true
The result to be returned if expression evaluates to true.

result_if_false
The result to be returned if expression evaluates to false.

Return Value(s)

The datatype of the result_if_true or result_if_false arguments.


Examples

Catgorize disk sizes of compute engine instances

SELECT iif(json_extract(disks, '$[0].diskSizeGb') > 9, "> 10GB", "<= 10GB") as disk_size
FROM google.compute.instances
WHERE project = 'stackql-demo'
AND zone = 'australia-southeast1-a';

For more information, see https://www.sqlite.org/lang_corefunc.html#iif