Re: How should I do this? - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: How should I do this?
Date
Msg-id 20020628121755.A15733@svana.org
Whole thread Raw
In response to Re: How should I do this?  (Laurent Duperval <lduperval@videotron.ca>)
List pgsql-general
On Thu, Jun 27, 2002 at 08:55:23PM -0400, Laurent Duperval wrote:
> On Thu, 27 Jun 2002 12:53:21 -0400, Martijn van Oosterhout wrote:
>
> > Have a look at DISTINCT ON. It works well for this sort of thing.
> >
>
> Yes, but if I have
>
> 1 2 3
> 2 2 3
> 3 3 4
> 4 2 3
> 5 2 3
>
> I want
>
> 1 2 3
> 3 3 4
> 4 2 3
>
> left in the database. I think using distint on would yield
>
> 1 2 3
> 3 3 4

Ah right. The problem is that DISTINCT ON requires that the fields be
distincted on be the same and the first few fields being sorted by. In the
hypothetical case you could do:

select distinct on (col2) select * from a order by col1;

But that isn't allowed. Maybe you will be a stored procedure or something.

--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> There are 10 kinds of people in the world, those that can do binary
> arithmetic and those that can't.



pgsql-general by date:

Previous
From: Curt Sampson
Date:
Subject: Re: Shared Memory Sizing
Next
From: Justin Clift
Date:
Subject: Suggestions for an update to the PHP manual?