This is experimental functionality, and as such subject to change. Use at your own risk!
Merge CASE .. WHEN and ELSE clauses
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
When a searched CASE expression's last WHEN
clause returns the same value as the ELSE
clause, then the WHEN
clause is redundant. If it's the only WHEN
clause, then the entire CASE
exression is redundant.
Using Settings.transformPatternsCaseMergeWhenElse
, the following transformations can be achieved:
-- With Settings.transformPatternsCaseMergeWhenElse active, this: SELECT CASE WHEN a = b THEN x WHEN c = d THEN y ELSE y END, CASE WHEN a = b THEN x ELSE x END FROM tab; -- ... is transformed into the equivalent expression: SELECT CASE WHEN a = b THEN x ELSE y END, x FROM tab;
Feedback
Do you have any feedback about this page? We'd love to hear it!