Skip to main content

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
  • $cases are evaluated in order; the first $condition that evaluates to true determines the result.
  • $else is optional. If no condition matches and no $else is provided, the result will be NULL.
  • All $expr return values should ideally share a common type or be coercible to a shared supertype.
  • You can nest $case expressions inside other expressions for more complex logic.
Example:
{
"$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 }
}
}