CASE Expression
A CASE expression defines branching logic. It evaluates conditions in sequence and returns the corresponding result for the first condition that matches. If no condition applies, an optional fallback ($else) value is used.
$case
Added in: indicate.dsl.dql@1.0.0
A conditional expression with one or more $cases, each containing a condition and a result. An optional $else defines the fallback result if no condition matches.
{
"$case": {
"$cases": [
{
"$condition": Object ( LogicalExpression ),
"$expr": Object ( Expression )
}
],
"$else": Object ( Expression )
}
}
note
$casesare evaluated in order; the first$conditionthat evaluates totruedetermines the result.$elseis optional. If no condition matches and no$elseis provided, the result will beNULL.- All
$exprreturn values should ideally share a common type or be coercible to a shared supertype. - You can nest
$caseexpressions inside other expressions for more complex logic.
- JSON
- SQL
{
"$case": {
"$cases": [
{
"$condition": {
"$binary": {
"$fn": "equals",
"$left": { "$identifier": "status" },
"$right": { "$scalar": "active" }
}
},
"$expr": { "$scalar": 1 }
},
{
"$condition": {
"$binary": {
"$fn": "equals",
"$left": { "$identifier": "status" },
"$right": { "$scalar": "inactive" }
}
},
"$expr": { "$scalar": 0 }
}
],
"$else": { "$scalar": -1 }
}
}
CASE
WHEN status = 'active' THEN 1
WHEN status = 'inactive' THEN 0
ELSE -1
END