3 ms·
The first feature in the deck is FILTER, which I can't help but mention I added support for (with a case/when fallback) to Django 2.0. So, if you're using the n
by orf 9y ago
The first feature in the deck is FILTER, which I can't help but mention I added support for (with a case/when fallback) to Django 2.0. So, if you're using the new Django release you can use this syntax on any aggregate/annotate via the filter kwarg[1] now.
There was one user report on the github PR that said FILTER was 10-15% faster over the equivalent CASE/WHEN, due to the null filtering I think. It's a shame only Postgres supports this supposedly standard syntax.
Edit: Heh, I initially got (stole) the idea of using FILTER + CASE from modern-sql.com[2], which is run by the author of this slide deck. So I guess I aught to thank Markus for this!
1. https://docs.djangoproject.com/en/2.0/ref/models/conditional-expressions/#conditional-aggregation https://docs.djangoproject.com/en/2.0/ref/models/conditional...
2. http://modern-sql.com/feature/filter http://modern-sql.com/feature/filter
- MarkusWinand 9y agoWelcome :)
- simonw 9y agoThat's really clever - I just blogged about it https://simonwillison.net/2018/Feb/3/conditional-aggregation-django-20/ https://simonwillison.net/2018/Feb/3/conditional-aggregation...
- orf 9y agoThank you Simon!