Remove redundant parentheses
I sometimes get code that looks like this:
WHERE (a = b) AND (c = d) AND (e = f)
Or even like this:
WHERE (((a = b) AND (c = d)) AND (e = f))
It would be great if SQL Prompt would have an option to remove all the redundant parentheses and reduce this to
WHERE a = b AND c = d AND e = f
Of course it would have to be smart enough to not remove parentheses that are needed when mixing AND and OR. So if I submit this code:
WHERE ((a = b) AND ((c = d) AND (e = f)))
... then the result should be:
WHERE a = b AND (c = d OR e = f)
Thank you for your suggestion.
We’ve reviewed this as part of our UserVoice triage.
Currently, we have no plans to implement this feature in the near future.
Kind Regards,
The Prompt Team
-
Hugo Kornelis commented
Matt: Good comment, and allow me to further specify my request: I woould not want it to remove parentheses that clarify the priority between AND and OR. Only parentheses that (a) serve no purpose for the meaning of the query, *and* (b) serve no purpose for clarfying the query without having to look up prioirty should be removed.
-
Matt Benham commented
I can see the appeal of this idea, but I think it could be more trouble than it is worth. Sometimes I like to put technically unnecessary brackets in to improve readability. For example I may put
WHERE (a=b AND c=d) OR e=f
Under this proposal it could reduce down to:
WHERE a=b AND c=d OR e=f
But personally I find it easier to understand with the brackets, and it may help junior devs to understand the code without getting confused over the precedence. I agree that it may be valid and useful to strip the inner-most brackets which have a single operator so that something ridiculous like:
WHERE ((a=b) AND (c=d)) OR (e=f)
still becomes
WHERE (a=b AND c=d) OR e=f