Standard SQL features where PostgreSQL beats its competitors
slideshare.net
slideshare.net
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...
It really is amazing how much you can prepare your data before it leaves your database, or how raw you can leave your data before sending it there, letting Postgres take care of it. I wonder how much middle code would be saved (PHP, Python, Perl, etc.) if more programmers knew more SQL, and especially if they chose Postgres more often. I also wonder why SQL seems to be the language that developers know least, even though it seems like it should be easiest, with its declarative, natural-sounding syntax. (I admit that the naturalness is deceptive. Just because "select color, count(1) from favorites where age < 13 having count(1) > 3 order by 1" sounds like English doesn't mean you can tell exactly what it will do before reading the manual.)
SQL is also a bit of a two-edged sword. You can do very powerful things with it that are infeasible in normal code, because they'd require round-tripping enormous quantities of data. OTOH it's easy to write code that performs and scales dreadfully, which will normally have knock-on effects across the whole production system, which is pretty scary.
There are usually multiple ways of writing what is semantically the same query, that perform quite differently, depending on how smart your target planner is. Despite the language being nominally declarative, you still need to keep in mind potential execution plans as you write the code, and verify on reasonably sized data sets that the plan you expected, or one better than it, was selected. It's been my experience that most developers don't have cost model estimation baked into their brains, so the more advanced cost estimation you need to do with a declarative language is even rarer.
Too bad I'm stuck on 9.1 for the time being which lack many of these really nice features.
The situation is getting so much better with logical decoding in recent version.
When the upgrade day finally come it will be like christmas with Lateral, Filter, JsonB, Percentile_Disc/Cont, and "upserts"
In particular really love the details on check constraints and null in Postgres.