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

ParameterTypeRequiredDescription
conditionBOOLEANYesBoolean expression to evaluate
true_valueTYesValue to return if condition is TRUE
false_valueTNoValue 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

Examples

Last update at: 2025/10/13 10:23:46