VeloDB Cloud
SQL Reference
SQL Functions
Scalar Functions
Conditional Functions
IF

IF

Description

Returns valueTrue when the condition is true, and returns valueFalseOrNull otherwise. The return type is determined by the result of the valueTrue/valueFalseOrNull expression.

Syntax

IF(<condition>, <value_true>, <value_false_or_null>)

Parameters

ParameterDescription
<condition>The boolean condition to evaluate.
<value_true>The value to return if <condition> evaluates to true.
<value_false_or_null>The value to return if <condition> evaluates to false.

Return Value

The result of the IF expression:

  • Returns valueTrue when the condition is true.
  • Returns valueFalseOrNull when the condition is false.

Examples

SELECT user_id, IF(user_id = 1, 'true', 'false') AS test_if FROM test;
+---------+---------+
| user_id | test_if |
+---------+---------+
| 1       | true    |
| 2       | false   |
+---------+---------+