Re: SELECT DISTINCT ON bug?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT DISTINCT ON bug?
Date: 2003-05-21 08:43:51
Message-ID: 20030521084351.GA15143@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, May 21, 2003 at 05:08:33PM +0900, Jean-Christian Imbeault wrote:
> Martijn van Oosterhout wrote:
> >
> >Drop the comma after the distinct on.
> >
> >SELECT distinct on(dai_genres.id) dsc from dai_genres,
>
> Ok, that worked. But accroding to "\h select" the syntax is:
>
> SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
> * | expression [ AS output_name ] [, ...]
>
>
> I gather that to mean SELECT DISTINCT ON (*) , ...
>
> Is the syntax give by "\h select" wrong or am I misinterpreting it?

You're misinterpreting it, though I must admit it does seem ambiguous. It
should be read as:

SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
{ * | expression [ AS output_name ] [, ...] }

See the {}.

Hope this helps,

--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> "the West won the world not by the superiority of its ideas or values or
> religion but rather by its superiority in applying organized violence.
> Westerners often forget this fact, non-Westerners never do."
> - Samuel P. Huntington

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Shridhar Daithankar 2003-05-21 08:46:47 Re: [HACKERS] about NULL
Previous Message zhangyue 2003-05-21 08:10:23 about NULL