3 ms·
I'm going to echo the comment about aggregate functions. I don't know how "hidden" they are, but they are one hell of a gem! At this point our one application
by Klathmon 9y ago
I'm going to echo the comment about aggregate functions.
I don't know how "hidden" they are, but they are one hell of a gem!
At this point our one application has more SQL code in it than application code. The postgresql json* aggregate functions make querying and formatting data easy enough that it can be done directly in the database and the result basically piped to the output without any need to reformat it.
I'll also add CTEs. They might also not be very "hidden" but they are fantastic once you get used to using them.
- sk5t 9y agoCTEs are very nice, although their performance characteristics push me over to lateral joins and subqueries by default.
- Klathmon 9y agolateral joins were already in the list so I skipped them, but I agree. I tend to reach for CTEs first as they are more readable in my opinion, but when there are perf issues, lateral joins are the way to get out of them. They almost feel like cheating!
- garyclarke27 9y agoI agree Lateral Joins are amazing, Ive started using them instead of CTEs a lot recently. Set returning functions are automatically lateral joined and make the logic much easier to follow than sub queries. Performance is great because Postgres happily inlines most SQL functions - unlike my experience with SQL Server (several years ago may have changed) where UDFs where munch slower than sub queries.