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: narrow result types with WHERE condition #596

Closed hemberger closed 1 year ago

hemberger commented 1 year ago

The WHERE condition of a SQL statement may narrow the type returned from a table. We can account for this when getting the type of each selected column.

Currently, the only implemented conditions are IS NOT NULL and IS NULL. This can be expanded in the future to support other binary operators and comparison operators.

Since the WHERE condition can narrow selections that are implicitly specified with an asterisk, we now expand the asterisk to an explicit list of columns so that we can perform the AST-based type resolution on them.