PostgreSQL v9 is out. It is greatly improved. Why should you be interested? If you were a petrol-head, you’d leap into a different car for that sunny weekend, feeling refreshed, even after a dreary week stuck in traffic in your commuting car. Well, I’m a SQL-Head, and it is a great pleasure to open the metaphorical garage doors, admire the metaphorical chrome, and take the metaphorical sporty convertible around the country roads. PostgreSQL was once the Lada, or Trabant of databases, but that’s all changed. It is fast, 64 bit, easy to install, and starts on first prod.
After a quick spin, it’s the Window functions that impress me the most. Whereas SQL Server’s adoption of the Window functions (think TOP, ROW_NUMBER, RANK, DENSE_RANK and NTILE) has been tentative, PostgreSQL, like many competitor RDBMSs, has a good implementation. You’re aware of what you’re missing when you try things out in PostgreSQL.. Window functions allow you to define the ordering for calculations without violating any relational principles, and, by doing so, eliminate the last remaining requirement for iterative or cursor-based calculations. They provide the means to perform calculations across sets of rows. SQL Server 2005 took the unfortunate course of implementing some, but not all, of the window functions. The essential ORDER BY clause of Window Aggregate functions, for example, was omitted, so you can’t do running totals. The wonderful LAG and LEAD offset functions are missing, so you have to do trend analysis a really clunky way. Functions that support statistical analysis aren’t implemented. You cannot name and reuse your windows, or have multiple windows in a query.
PostgreSQL, by contrast, manages to exploit the full use of Window Functions in its optimiser to produce fast queries. Everything seems to work fine. After trying out several examples, it was a wrench to go back to SQL Server 2008 to do the sort of operations that are so simple to perform with full support for window functions.
It was like going back into the company car on Monday after a weekend cruising in a sporty rag-top