Re: Windowing Function Patch Review -> Standard Conformance

From: "Vladimir Sitnikov" <sitnikov(dot)vladimir(at)gmail(dot)com>
To: "David Rowley" <dgrowley(at)gmail(dot)com>
Cc: "Hitoshi Harada" <umi(dot)tanuki(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org, heikki(dot)linnakangas(at)enterprisedb(dot)com
Subject: Re: Windowing Function Patch Review -> Standard Conformance
Date: 2008-11-05 01:02:57
Message-ID: 1d709ecc0811041702m7fb8f515gfefb357e28585a63@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Quoted from SQL:2008
> "If CUME_DIST is specified, then the relative *rank *of a row R is defined
> as
> NP/NR, where NP is defined
> to be the number of rows preceding or peer with R in the window ordering of
> the window partition of R
> and NR is defined to be the number of rows in the window partition of R."
>
> I guess there is a difference between "row_number" and "number of rows
preceding or peer with R"

"number of rows preceding or peer with R" == count(*) over (order by salary)

As far as I understand, the following query should calculate cume_dist
properly (and it does so in Oracle):

SELECT name,CAST(r AS FLOAT) / c, cd
FROM (SELECT name,
COUNT(*) OVER(ORDER BY salary) as r,
COUNT(*) OVER() AS c,
CUME_DIST() OVER(ORDER BY salary) AS cd
FROM employees
) t;

Sincerely yours,
Vladimir Sitnikov

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Unicron 2008-11-05 01:12:15 Questions about patch "Table command"
Previous Message David Rowley 2008-11-05 00:25:18 Windowing Function Patch Review -> Standard Conformance