case

Description

Return a matching result if any of the multiple given conditions are true.

If no condition matches, return NULL. Conditions and results are evaluated in pairs in order of argument.

For a default or otherwise case, add the condition true and whatever value you want to the end of the cases.

See also if.

Return type

result

Domain

This is a scalar function (calculates a single output value for a single input row.)

Categories

Usage

case(condition_1, result_1, condition_2, result_2, ...)

Argument

Type

Optional

Repeatable

Restrictions

condition

bool

no

yes

none

result

storable

no

yes

none

Examples

filter b=case(a=1, 'one', a=2, 'two', true, 'something else')

Filter to return rows where, if a is 1, b equals ‘one’, else if a is 2, b equals ‘two’, else b equals ‘something else’. The default case is supplied at the end, using the simple condition true.