Re: WITHIN GROUP patch

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: Atri Sharma <atri(dot)jiit(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Vik Fearing <vik(dot)fearing(at)dalibo(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: WITHIN GROUP patch
Date: 2013-12-08 18:04:16
Message-ID: 14195.1386525856@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> writes:
> There's also the question of ungrouped vars, maybe. Consider these two
> queries:

> select array(select a+sum(x) from (values (0.3),(0.7)) v(a) group by a)
> from generate_series(1,5) g(x);

> select array(select percentile_disc(a) within group (order by x)
> from (values (0.3),(0.7)) v(a) group by a)
> from generate_series(1,5) g(x);

> In both cases the aggregation query is the outer one; but while the first
> can return a value, I think the second one has to fail (at least I can't
> see any reasonable way of executing it).

Hm, interesting. So having decided that the agg has level 1, we need to
reject any level-0 vars in the direct parameters, grouped or not.

We could alternatively decide that the agg has level 0, but that doesn't
seem terribly useful, and I think it's not per spec either. SQL:2008
section 6.9 <set function specification> seems pretty clear that
only aggregated arguments should be considered when determining the
semantic level of an aggregate. OTOH, I don't see any text there
restricting what can be in the non-aggregated arguments, so maybe the
committee thinks this case is sensible? Or they just missed it.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2013-12-08 18:12:11 Re: dblink performance regression
Previous Message Pavel Stehule 2013-12-08 17:01:40 Re: plpgsql_check_function - rebase for 9.3