Re: BUG #17232: DISTINCT ON does not allow AS - Mailing list pgsql-bugs

From Alvaro Herrera
Subject Re: BUG #17232: DISTINCT ON does not allow AS
Date
Msg-id 202110161459.hufnhzw4bosn@alvherre.pgsql
Whole thread Raw
In response to BUG #17232: DISTINCT ON does not allow AS  (PG Bug reporting form <noreply@postgresql.org>)
List 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)



pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BUG #17232: DISTINCT ON does not allow AS
Next
From: PG Bug reporting form
Date:
Subject: BUG #17233: Incorrect behavior of DELETE command with bad subquery in WHERE clause