Re: writing a MIN(RECORD) aggregate

Поиск
Список
Период
Сортировка
От Sam Mason
Тема Re: writing a MIN(RECORD) aggregate
Дата
Msg-id 20080325191807.GI6870@frubble.xen.chris-lamb.co.uk
обсуждение исходный текст
Ответ на Re: writing a MIN(RECORD) aggregate  (Gregory Stark <stark@enterprisedb.com>)
Ответы Re: writing a MIN(RECORD) aggregate  (Gregory Stark <stark@enterprisedb.com>)
Список pgsql-hackers
On Tue, Mar 25, 2008 at 06:58:06PM +0000, Gregory Stark wrote:
> "Sam Mason" <sam@samason.me.uk> writes:
> >   SELECT i, MIN(k) OVER (PARTITION BY j)
> >   FROM tbl
> >   GROUP BY i;
> >
> > This is obviously wrong, but I don't see how to get to where I need to
> > be.
> 
> I'm not entirely sure myself. I think it might involve RANK OVER j though.

The main thing I wanted to avoid was an explosion of sub-queries that
you get with DISTINCT ON style queries.  For example, with record style
syntax, I can do:
 SELECT i, (MIN((j,k))).k AS ka, (MIN((mycode(j),k))).k AS kb FROM tbl GROUP BY i;

whereas using DISTINCT ON I'd have to do:
 SELECT a.i, a.k AS ka, b.k as kb FROM (   SELECT DISTINCT ON (i) i, k   FROM tbl   ORDER BY i, j) a, (   SELECT
DISTINCTON (i) i, k   FROM tbl   ORDER BY i, mycode(j)) b WHERE a.i = b.i;
 

Which gets unmanageable quickly.  Any idea how window functions would
cope with this sort of complexity?  Or is this what you meant by:

> I suspect it will look more like the DISTINCT ON solution than the min(record)
> solution.


Thanks, Sam


В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Pavel Stehule"
Дата:
Сообщение: Re: Text <-> C string
Следующее
От: "Pavel Stehule"
Дата:
Сообщение: Re: Wiki patch queue