"Ted Holzman" <tholzman(at)fhcrc(dot)org> wrote:
> AGGREGATE functions don't appear to respond to LIMIT clauses.
Not a bug. LIMIT affects how many rows are in the result set the
LIMIT qualifies.
> select sum(generate_series)
> from generate_series(1,10) limit 3;
> sum
> -----
> 55
> (1 row)
>
> I was expecting the sum to be 6.
The LIMIT is applied to the final result set, which is only one row,
so the LIMIT has nothing to do. If you wanted to limit how many rows
went into the aggregate function, you'd need to do something like
this:
select sum(generate_series)
from (select generate_series(1,10) limit 3) x;
sum
-----
6
(1 row)
-Kevin