zzzeek/sqlalchemy — pull request #134 by everilae (2014-09-10 08:50:46+00:00)
Title: Postgresql 9.4 aggregate filter syntax support

Since postgresql 9.4 is implementing the SQL standard FILTER clause for controlling rows passed to an aggregate function, thought it would be nice to have it available. Somewhat equal results have been possible with func.(case(...)) and will continue to be for DBs not supporting the clause. Custom compiler instructions may even implement a backup for missing support (translating the FILTER clause to func(CASE WHEN ... END) ).

Usage would be along the lines of `.over` and `Query.filter`:

func.count(1).filter(MyTable.value % 7 == 0).label('sevens')

and the result

COUNT(1) FILTER (WHERE mytable.value % 7 = 0) AS sevens