Re: Documentation, window functions - Mailing list pgsql-hackers

From Dennis Björklund
Subject Re: Documentation, window functions
Date
Msg-id 2a28107e5b0a169b89031043a5b3e326.squirrel@zigo.org
Whole thread Raw
In response to Re: Documentation, window functions  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Documentation, window functions  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
> On Wed, Sep 22, 2010 at 6:03 AM, Dennis Björklund <db@zigo.dhs.org> wrote:
> But I confess that I'm sort of murky on how ORDER affects the window
> frame, or how to rephrase this more sensibly.

The rows included in the calculation of the window function are per default

RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW

where CURRENT ROW include all the rows that are equal to the row you are
at according to the ordering. So if you say order by name then all the
rows up to your name and all rows with the same name are included, not
later rows.

If you don't have any ordering, then all rows are "equal" and all rows are
included in the computation. That's why your example behaved like it did.

At least that's my understanding of how these things work. I've not used
window functions very much myself.

This is fairly difficult stuff and it probably don't belong in a tutorial
but the current wording suggest that you can add any ordering and it won't
affect the result. That is also a bad since it might teach people the
wrong thing.

/Dennis




pgsql-hackers by date:

Previous
From: KaiGai Kohei
Date:
Subject: Re: security label support, revised
Next
From: "Joshua D. Drake"
Date:
Subject: Re: git cherry-pick timestamping issue