Re: onlyvalue aggregate (was: First Aggregate Funtion?) - Mailing list pgsql-hackers

From Greg Stark
Subject Re: onlyvalue aggregate (was: First Aggregate Funtion?)
Date
Msg-id CAM-w4HM2UGPWf1DhtJVUPrrp5Bg_AyD6jfTkvOedCpt-x35i6A@mail.gmail.com
Whole thread Raw
In response to Re: onlyvalue aggregate (was: First Aggregate Funtion?)  (Marko Tiikkaja <marko@joh.to>)
List pgsql-hackers
On Wed, Oct 28, 2015 at 5:03 PM, Marko Tiikkaja <marko@joh.to> wrote:
> SELECT a, sum(amount), onlyvalue(rolling_count)
> FROM
> (
>     SELECT a, amount, count(*) OVER (ORDER BY a) AS rolling_count
>     FROM tbl
> ) ss
> GROUP BY a;


The same thing would happen even in the more common case of having
functionally dependent columns if they happen to be buried in a
subquery. That might well be convenient if you have some expression
you want to use in multiple aggregates such as:

SELECT pk, acol, avg(x), min(x), max(x)  FROM (     SELECT a,pk, a,acol, b.c+b.d+b.e AS x         FROM a JOIN b ON
(a.pk= b.fk)  ) GROUP BY pk
 

Postgres would happily accept that if you collapsed the subquery and
ran the group by directly on the join but the subquery in between is
actually enough to hide the functional dependency information so it
complains that acol is not functionally dependent on the group by
column.

-- 
greg



pgsql-hackers by date:

Previous
From: Craig Ringer
Date:
Subject: Re: Identify user requested queries
Next
From: Amit Kapila
Date:
Subject: Re: [DESIGN] ParallelAppend