-
Notifications
You must be signed in to change notification settings - Fork 112
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
Support for filtered aggregations #356
Labels
Comments
Related comment - #355 (comment). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
SQL:2003 introduced filtered aggregations, e.g.
SELECT COUNT(*) FILTER(WHERE foo > 0)
. They're currently supported in Postgres and SQLite.If I want to use this syntax in Jet, I have to resort to
Raw
, which is inconvenient. I'd like to be able to build theFILTER(WHERE ...)
clause in the same way I build any otherWHERE
clause.To be fair, the ANSI SQL form of the
FILTER
clause is in many cases essentially syntactic sugar, and it can usually be emulated with aCASE
statement, but this is not always true. Taking theCASE
approach typically relies on aggregate functions ignoring nulls, but this does not work with functions such as Postgres'json_arrayagg
, where nulls may or may not be a desired part of the output. Postgres also extends standard SQL by allowing subqueries likeEXISTS()
in theFILTER
clause, and that can't be emulated with aCASE
statement either.Possible solution
Aggregate functions in dialects that support this syntax could return an extended
Expression
object that would allow adding aFILTER
clause, similar to how the windowOVER
clause is implemented. Rough sketch:The text was updated successfully, but these errors were encountered: