I’ve shared my enthusiasm for PostgreSQL’s FILTER clause and highlighted reporting examples involving conditional aggregation and date ranges. The examples connect to broader postgres sql techniques and readable sql practices.
I absolutely love the FILTER clause within Postgres and SQL generally.
I first used FILTER probably 2 years ago.
I said I can't believe I lived without using it for so long.
I said the @crunchydata twitter feed is on fire with great content lately.
I joked, “maybe one day.”
I said I really do love me some FILTER in Postgres.
In a Crunchy Data example I shared, invoices are grouped by month to calculate total, collected, and outstanding amounts. The post compares conditional sums using CASE in each field with the FILTER clause. Another shared example describes using PostgreSQL INTERVAL for report date ranges, including a 90-day lookback; these are examples from @crunchydata, not SQL explanations I claimed as my own.
Related: window functions, creative sql projects, choosing and using postgres