Re: window function count(*) and limit - Mailing list pgsql-hackers

From Tom Lane
Subject Re: window function count(*) and limit
Date
Msg-id 22771.1287852169@sss.pgh.pa.us
Whole thread Raw
In response to window function count(*) and limit  (Jesper Krogh <jesper@krogh.cc>)
Responses Re: window function count(*) and limit
List pgsql-hackers
Jesper Krogh <jesper@krogh.cc> writes:
> I have been puzzled about the evaluation order when using window
> functions and limit.

It's basically FROM -> WHERE -> window functions -> LIMIT.

> I expected it to either count to 3 or blow up and tell me that count(*)
> wasn't a window function.

Any aggregate function can be used as a window function.  It just
aggregates over the whole partition (which in this case is all 8
rows that satisfy the WHERE).

LIMIT is supposed to truncate the output at a specified number of
rows, not change what is in those rows; so ISTM that this evaluation
order is the expected one.  If you want to put a LIMIT in front of
the aggregates/window functions, put it in a sub-select.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Jesper Krogh
Date:
Subject: window function count(*) and limit
Next
From: Jesper Krogh
Date:
Subject: Re: window function count(*) and limit