Skip to Main Content

Filter clause for aggregate functions

Martin PreissFeb 4 2015 — edited May 28 2016

Having written expressions of the form "sum( case when ... then 1 else 0 end )" a million times I would appreciate the introduction of the SQL:2003 Filter clause - as it has been introduced in recent postgres releases:

sum(...) filter (where ...)

Not a very important change, but I assume this should be a quite simple task - being merely syntactic sugar - and it would brings us closer to SQL:2003 and make this kind of aggregations more simple to understand.

Furthermore I would appreciate the introduction of a decent search function here - so I could be sure that this proposal has not already been made...

A concise explanantion of the filter clause in SQL:2003 can be found in Markus Winand's article: filter — Selective Aggregates

Comments
Post Details
Added on Feb 4 2015
9 comments
1,872 views