Why not just wrap things that might need them in parentheses by default? It doesn't hurt to have extra parens, but it does hurt not to have them. I think it's a nicer and easier API to have it work without having to remember (or know) to use :nest
. If people need to opt-in to parentheses with something like :nest
, then it's going to lead to bugs for library users where it works most of the time, but fails in edge cases where parentheses would have been required
Since Cam also posted that comment on issue #279, I'll post my response here for feedback from y'all: Well, you can't just wrap things in parentheses arbitrarily in SQL -- that was the original problem in #107 because there was an extra set of parens. And you don't need the parens in the vast majority of cases with union. I believe I've also run into a case, in MySQL, where if you add the parens, in some situations you also need to add an alias, even if nothing else in the query actually uses it. That sort of thing makes me very wary of adding parens by default unless they really are needed. V1 and V2 already have a different approach for this where I'm removing external parens (from where they're definitely not needed) and adding them internally where they are safe. I'll leave this open while V2 is being worked on and see what feedback I get from other users. It's trivial to change the behavior for all the set operations without changing anything else.