Re: BUG #17232: DISTINCT ON does not allow AS

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: kyle(at)lahnakoski(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17232: DISTINCT ON does not allow AS
Date: 2021-10-16 14:59:15
Message-ID: 202110161459.hufnhzw4bosn@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2021-Oct-15, PG Bug reporting form wrote:

> The following SQL has an unexpected syntax error
>
> SELECT DISTINCT ON (col) AS col, col2 FROM test

Well, the "ON (col)" part is not an output column -- it's just the
specification of the column that you want distinctness over. I suspect
you mean

SELECT DISTINCT ON (col) col AS col, col2 FROM test

... which looks like a pretty bogus thing to do, since you have no say
on *which* values of col2 are you going to get for each distinct value
of col. But ... it gives *some* result, at least.

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Pensar que el espectro que vemos es ilusorio no lo despoja de espanto,
sólo le suma el nuevo terror de la locura" (Perelandra, C.S. Lewis)

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2021-10-16 19:41:52 BUG #17233: Incorrect behavior of DELETE command with bad subquery in WHERE clause
Previous Message David G. Johnston 2021-10-15 23:01:08 Re: BUG #17232: DISTINCT ON does not allow AS