Re: Top N within groups?

From: Klint Gore <kgore4(at)une(dot)edu(dot)au>
To: pgsql-general(at)postgresql(dot)org, kleptog(at)svana(dot)org
Subject: Re: Top N within groups?
Date: 2008-07-14 05:27:32
Message-ID: 487AE3C4.3000500@une.edu.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Martijn van Oosterhout wrote:
> On Fri, Jul 11, 2008 at 01:24:28PM +1000, Klint Gore wrote:
> > [thinking out loud]
> > Can someone familiar with the source for DISTINCT ON comment on how hard
> > it would be to add another parameter to return more than one row?
>
> From a programming point of view, it wouldn't be too hard. However,
> deciding what syntax to use is a another question entirely. I think
> your suggestion of FOR isn't good (ambiguous syntax, 'for' could be a
> column name), but I can't think of a better one.
>
'for' is a reserved key word so can't be a column name.

http://www.postgresql.org/docs/8.3/interactive/sql-keywords-appendix.html

postgres=# create table foo (for int);
ERROR: syntax error at or near "for"

The worst I think you could get would be
select distinct on ("for") for 4 "for" from table4 for update;

but even then, I think the parser could work out what you want.

klint.

--
Klint Gore
Database Manager
Sheep CRC
A.G.B.U.
University of New England
Armidale NSW 2350

Ph: 02 6773 3789
Fax: 02 6773 3266
EMail: kgore4(at)une(dot)edu(dot)au

In response to

Browse pgsql-general by date

  From Date Subject
Next Message ken andrew 2008-07-14 09:47:20 Installing PostgreSQL without using CygWin
Previous Message ken andrew 2008-07-14 05:27:28 Installing PostgreSQL without using CygWin