if function

Returns expr1 if cond is true, or expr2 otherwise.

Syntax

if(cond, expr1, expr2)

Arguments

  • cond: A BOOLEAN expression.

  • expr1: An expression of any type.

  • expr2: An expression that shares a least common type with expr1.

Returns

The result is the common maximum type of expr1 and expr2.

This function is a synonym for iff function.

Examples

> SELECT if(1 < 2, 'a', 'b');
 a