staabm / phpstan-dba

PHPStan based SQL static analysis and type inference for the database access layer
https://staabm.github.io/archive.html#phpstan-dba
MIT License
250 stars 17 forks source link

SQL AST: fix aggregate functions with GROUP BY #599

Closed hemberger closed 1 year ago

hemberger commented 1 year ago

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.