Add "having" Support to Select Statements #550
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for "having" clauses in select statements. The PR includes a refactoring of the "where" support so we can reuse the and/or logic and rendering that is already present in the "where" clause support. This because "having" and "where" are essentially the same.
One slight behavior change with this refactoring is that the renderer will now remove a useless open/close parentheses around certain rendered where clauses. Previously it was possible to have a rendered where clause like this:
The renderer will now remove the open/close parentheses in a case like this.
The "having" support is not as full featured as the "where" support in that we don't support independent and reusable having clauses, and we don't support composable having functions. If you have a reasonable use case for that kind of support, please let us know.
In the Java DSL, a "having" clause can only be coded after a "group by" clause - which is a reasonable restriction as "having" is only needed if there is a "group by".
In the Kotlin DSL, the "group by" restriction is not present because of the free form nature of that DSL - but you should probably only use "having" if there is a "group by". Also note that the freestanding "and" and "or" functions in the Kotlin DSL still only apply to the where clause.
Resolves #418