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
255 stars 17 forks source link

SQL AST: COUNT cannot return null #584

Closed hemberger closed 1 year ago

hemberger commented 1 year ago

Remove nullability from the PositiveIntReturnTypeExtension for the COUNT function case.

If there are no matching rows, COUNT() returns 0. COUNT(NULL) returns 0.

(source: https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_count)

staabm commented 1 year ago

ah interessting. this changed recently, because I had the impression count would lead to null on empty result sets.

testing it again seems this is not the case:

grafik
staabm commented 1 year ago

thank you