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

SQL AST: fix aggregate functions with GROUP BY #599

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

hemberger
Copy link
Contributor

Aggregate functions that return null on an empty set will instead
return no result if the expression has a GROUP BY clause.

This currently affects the Avg, Sum, and MinMax return type extensions.

We also update Sum to always allow a null result without GROUP BY, as per https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_sum:

If there are no matching rows, or if expr is NULL, SUM() returns NULL.

Aggregate functions that return null on an empty set will instead
return no result if the expression has a GROUP BY clause.

This currently affects the Avg, Sum, and MinMax return type exts.

Also, SUM can always return NULL if there is no GROUP BY:

> If there are no matching rows, or if expr is NULL, SUM() returns NULL.

https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_sum
Copy link
Owner

@staabm staabm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome

@staabm staabm merged commit e01951c into staabm:main Apr 13, 2023
@hemberger hemberger deleted the group-by branch April 14, 2023 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants