When using aggregation functions in PostgreSQL, we have the option of including a FILTER
clause. This clause allows us to narrow down – or filter – the rows that are fed to the aggregate function.
This can be be a handy way to provide functionality that we might otherwise need to use a CASE
statement or perhaps a CTE.
In this article, we’ll take a look at PostgreSQL’s FILTER
clause, and see how it can simplify our SQL queries by replacing CASE
statements with more concise code.