Re: window function count(*) and limit

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jesper Krogh <jesper(at)krogh(dot)cc>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: window function count(*) and limit
Date: 2010-10-23 16:42:49
Message-ID: 22771.1287852169@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jesper Krogh <jesper(at)krogh(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jesper Krogh 2010-10-23 17:55:14 Re: window function count(*) and limit
Previous Message Jesper Krogh 2010-10-23 16:25:33 window function count(*) and limit