Re: Windowing Function Patch Review -> Standard Conformance - Mailing list pgsql-hackers

From Vladimir Sitnikov
Subject Re: Windowing Function Patch Review -> Standard Conformance
Date
Msg-id 1d709ecc0811041702m7fb8f515gfefb357e28585a63@mail.gmail.com
Whole thread Raw
In response to Windowing Function Patch Review -> Standard Conformance  ("David Rowley" <dgrowley@gmail.com>)
Responses Re: Windowing Function Patch Review -> Standard Conformance
List 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

pgsql-hackers by date:

Previous
From: "David Rowley"
Date:
Subject: Windowing Function Patch Review -> Standard Conformance
Next
From: Unicron
Date:
Subject: Questions about patch "Table command"