multiIf
Multi-branch conditional — clean CASE WHEN replacement for status mapping.
Signature
multiIf(cond1, val1, cond2, val2, ..., else): TReturns
Same type as value branches
What it does
Evaluates conditions left to right and returns the value of the first true condition. The final argument is the default (else) value. The ClickHouse replacement for CASE WHEN…THEN…ELSE.
multiIf() is ClickHouse's multi-branch conditional. It evaluates each condition in order and returns the associated value for the first true condition. Unlike if(), it is short-circuit — later branches are not evaluated if an earlier one matches. This makes it safe to use with potentially NULL-returning expressions in later branches.
Notes
- Short-circuit: once a condition is true, later conditions are not evaluated.
- All value branches must return the same (or compatible) type.
- For simple two-branch conditionals, if() is more readable.
Example SQL
multiIf in ClickHouse SQL
TypeScript with hypequery
Use multiIf in a typed TypeScript query
hypequery gives you a type-safe query builder for ClickHouse. The generated schema maps your ClickHouse columns to TypeScript types, and raw SQL expressions let you incorporate functions like multiIf when you need them inside a builder query.
Common questions
What developers search for with multiIf
ClickHouse CASE WHEN TypeScript
multiIf(cond1, val1, cond2, val2, ..., default) is the ClickHouse equivalent of CASE WHEN. It is more concise and short-circuits on the first match.
FAQ
Frequently asked questions about multiIf
Does multiIf() short-circuit evaluate?
Yes — once a condition is true, later conditions and their values are not evaluated. This makes it safer than nested if() for NULL-sensitive expressions.
Related guides
Next step
Use multiIf in a type-safe TypeScript query
hypequery generates TypeScript types from your ClickHouse schema. Use multiIf alongside the builder, and reach for raw SQL expressions when the function is not exposed as a dedicated helper.