You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have nothing against having a switch statement, but ClickHouse also has multiIf function with short-circuit-function-evaluation. It is often more readable than a switch and addresses your concerns about "evaluate all conditions and cases before choosing a correct one".
Or to make expr closer to golang and implement switch in the exact same semantics.
I very much would like to see multi-line expressions happen, so it would make sense to have switches to be an expression as well, e.g. in Ruby:
case x
when 1..5
"It's between 1 and 5"
when 6
"It's 6"
when "foo", "bar"
"It's either foo or bar"
else
"You gave me #{x} -- I have no idea what to do with that."
end
The key point is that it evaluates to an expression. The syntax does not matter.
Activity
vmihailenco commentedon Aug 10, 2024
I have nothing against having a switch statement, but ClickHouse also has multiIf function with short-circuit-function-evaluation. It is often more readable than a switch and addresses your concerns about "evaluate all conditions and cases before choosing a correct one".
antonmedv commentedon Aug 10, 2024
While switch statement is easy to understand and implement, maybe we need to consider adding "match" expression instead.
Or to make expr closer to golang and implement switch in the exact same semantics.
vmihailenco commentedon Aug 10, 2024
I very much would like to see multi-line expressions happen, so it would make sense to have switches to be an expression as well, e.g. in Ruby:
The key point is that it evaluates to an expression. The syntax does not matter.
antonmedv commentedon Aug 10, 2024
I see. This makes sense. 👍🏻
tinboxw commentedon Feb 8, 2025
When can it be achieved approximately?