Re: Special grouping on sorted data. - Mailing list pgsql-sql

From Tom Lane
Subject Re: Special grouping on sorted data.
Date
Msg-id 17094.1222223123@sss.pgh.pa.us
Whole thread Raw
In response to Re: Special grouping on sorted data.  (Nicolas Beuzeboc <nicolasb@norchemlab.com>)
List pgsql-sql
Nicolas Beuzeboc <nicolasb@norchemlab.com> writes:
> I which distinct on was more flexible, it's not happy when the order by 
> set is different than the distinct on set.
> I would like to be able to write select distinct on (b,n) b,n,stamp from 
> table where ... order by stamp;

Well, no, because it's defined to use the ORDER BY order to determine
which row is "first" within each DISTINCT ON group.

There is an easy workaround for this, which is to sort the rows again in
an outer select:

select * from
( select distinct on (b,n) b,n,stamp from  table where ... order by b,n,stamp ) ss
order by stamp;
        regards, tom lane


pgsql-sql by date:

Previous
From: Nicolas Beuzeboc
Date:
Subject: Re: Special grouping on sorted data.
Next
From: "Oliveiros Cristina"
Date:
Subject: Re: exclusion query