-
-
Notifications
You must be signed in to change notification settings - Fork 755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New rule: Nested CASEs with conditions on the same column #1799
Comments
Is there ever a situation where nested CASE statements are needed? Since the CASE statement is effectively an IF/ELIF/ELSE structure you could reduce all nested case statements? CASE
WHEN species = “Cat” THEN “Meow”
ELSE
CASE
WHEN number_of_legs = 8 THEN “<spider_sounds>”
END
END as sound is equivalent to CASE
WHEN species = “Cat” THEN “Meow”
WHEN number_of_legs = 8 THEN “<spider_sounds>”
END as sound So we can make a rule to stop the use of nested case statements and replace them as above. |
Nested
I think the generalized rule for "can this be de-nested" is: Are the nested conditions mutually exclusive to the outer condition? |
I've got a preliminary implementation of this rule in a branch. It builds on some unmerged work (PR #2126), so this new rule won't be completed until that other PR reviewed and merged. The approach I took for implementing it is to look for |
When conditions in iterative
CASE
statements are on the same column they should be simplified without any cost i.e.is really just
The text was updated successfully, but these errors were encountered: