IF
All functions > CONDITIONAL > IF
Returns one value if a condition is true, another if false
Syntax
IF(condition: BOOLEAN, true_value: T, false_value: T) → T
sql
Type Parameters:
T
: Any expression type
Arguments
Parameter | Type | Required | Description |
---|---|---|---|
condition | BOOLEAN | Yes | Boolean expression to evaluate |
true_value | T | Yes | Value to return if condition is TRUE |
false_value | T | No | Value to return if condition is FALSE (optional, defaults to NULL) |
Returns
Same type as true_value/false_value - returns true_value if condition is TRUE, false_value if FALSE, NULL if condition is NULL
Notes
- Condition must evaluate to BOOLEAN
- true_value and false_value must be of compatible types
- If condition is NULL, returns NULL
- If false_value is omitted, returns NULL when condition is FALSE
- Short-circuits evaluation: only evaluates the branch that will be returned