CASE_WHEN

All functions > CONDITIONAL > CASE_WHEN

Returns the result of the first condition that evaluates to true

Syntax

CASE_WHEN(when: ARRAYBOOLEAN, then: ARRAY<T>, else: T) → T
sql

Type Parameters:

  • T: Any expression type

Arguments

ParameterTypeRequiredDescription
whenARRAYBOOLEANYesArray of boolean conditions to evaluate in order
thenARRAY<T>YesArray of values to return, corresponding to each when condition
elseTNoValue to return if no condition is true (optional)

Returns

Same type as then values - returns the value corresponding to the first true condition, or else value if none match

Notes

  • Evaluates conditions in order and returns the first matching result
  • when and then arrays must have the same length
  • If no condition matches and else is not provided, returns NULL
  • Short-circuits: stops evaluating once a condition is true
  • All then values and else value must be of compatible types

Examples

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