Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

SQL Server's implementation of Window Functions

By Phil Factor,

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

Total article views: 583 | Views in the last 30 days: 4
 
Related Articles
FORUM

PostgreSQL

PostgreSQL PostgreSQL has always been interesting to me and has captivated me more than MySQL...

FORUM

lag function calculation

llag function calculation

ARTICLE

Reaping the benefits of the Window functions in T-SQL

Exploring the potential benefits of the T-SQL Window functions (OVER, LAG, and LEAD) in this piece. ...

FORUM

PostgreSQL

I would love to hear from anyone who has worked w/SQL Server and PostgreSQL. We are looking at movi...

ARTICLE

High-Performance Transact-SQL with Window Functions

Window functions are more intuitive and simpler in many cases than alternative SQL methods.

Tags
database weekly    
editorial    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones