Skip to content
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

Add "having" Support to Select Statements #550

Merged
merged 12 commits into from Nov 15, 2022

Conversation

jeffgbutler
Copy link
Member

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:

where (a < 2 and b > 3)

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

@jeffgbutler jeffgbutler added this to the 1.5.0 milestone Nov 15, 2022
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 2e90ca1 on jeffgbutler:having-support into 58e02cb on mybatis:master.

@jeffgbutler jeffgbutler merged commit e773c05 into mybatis:master Nov 15, 2022
@jeffgbutler jeffgbutler deleted the having-support branch November 15, 2022 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Why not support having?
2 participants