Re: Planning aggregates which require sorted or distinct

From: Markus Schiltknecht <markus(at)bluegap(dot)ch>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Gavin Sherry <swm(at)alcove(dot)com(dot)au>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Planning aggregates which require sorted or distinct
Date: 2007-01-20 10:12:00
Message-ID: 45B1EAF0.1030809@bluegap.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Tom Lane wrote:
>> select empno, rank() over (order by salary) as srank,
>> rank() over (order by age) as arank
>> from employees order by empno;
>
> Eeek. This seems like the worst sort of action-at-a-distance. How does
> rank() know what value it's supposed to report the rank of?

All of these ranking aggregate functions (rank, dense_rank,
percent_rank, cume_dist and row_number) are normally used without any
arguments, see examples in [1] or [2]. However, they explicitly require
an ORDER BY clause anyway, so I suppose they need one with exactly *one*
argument? Does the standard say anything more explicit? Or should those
functions just take the first ORDER BY argument?

I.e. what should the following query do? Is it a legal query at all?

select empno, cume_dist() over (order by salary, age) as rank,
from employees order by empno;

Regards

Markus

[1]: SQL Anywhere Server - SQL Reference, Window Clause:
http://www.ianywhere.com/developer/product_manuals/sqlanywhere/1000/en/html/dbrfen10/rf-window-clause-statement.html

[2]: A techonthenet.com article about cume_dist() function:
http://www.techonthenet.com/oracle/functions/cume_dist.php

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2007-01-20 10:28:08 Re: Planning aggregates which require sorted or distinct
Previous Message Adriaan van Os 2007-01-20 09:20:52 Re: BUG #2907: pg_get_serial_sequence quoting