CASE_WHEN_VALUE

All functions > CONDITIONAL > CASE_WHEN_VALUE

Returns the result corresponding to the first matching value in a simple case expression

Signatures

Returns: the value corresponding to the first match, or else value if none match

CASE_WHEN_VALUE(when_base: T, values_to_match: ARRAY<T>, then: ARRAY<U>, else: U) → U
sql
ParameterTypeRequiredDescription
when_baseTYesExpression to compare against values
values_to_matchARRAY<T>YesArray of values to match against when_base
thenARRAY<U>YesArray of values to return, corresponding to each match value
elseUYesValue to return if no value matches

Notes

  • Compares when_base against each value in values_to_match using equality
  • Returns the corresponding then value for the first match
  • values_to_match and then arrays must have the same length
  • All then values and else value must be of compatible types
  • More concise than CASE_WHEN for simple equality comparisons

Examples

FeatureQL
SELECT
    f1 := CASE_WHEN_VALUE(2, ARRAY[1, 2, 3], ARRAY['a', 'b', 'c'], 'z'),  -- Value 2 matches position 2, returns 'b'
    f2 := CASE_WHEN_VALUE(5, ARRAY[1, 2, 3], ARRAY['a', 'b', 'c'], 'z'),  -- Value 5 not in array, returns else value
    f3 := CASE_WHEN_VALUE('cat', ARRAY['dog', 'cat', 'bird'], ARRAY[1, 2, 3], 999)  -- String matching
;
Result
f1 VARCHARf2 VARCHARf3 BIGINT
bz2

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19