pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17232: DISTINCT ON does not allow AS
3+ messages / 3 participants
[nested] [flat]

* BUG #17232: DISTINCT ON does not allow AS
@ 2021-10-15 22:41 PG Bug reporting form <noreply@postgresql.org>
  2021-10-15 23:01 ` Re: BUG #17232: DISTINCT ON does not allow AS David G. Johnston <david.g.johnston@gmail.com>
  2021-10-16 14:59 ` Re: BUG #17232: DISTINCT ON does not allow AS Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 2 replies; 3+ messages in thread

From: PG Bug reporting form @ 2021-10-15 22:41 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: kyle@lahnakoski.com

The following bug has been logged on the website:

Bug reference:      17232
Logged by:          Kyle Lahnakoski
Email address:      kyle@lahnakoski.com
PostgreSQL version: 14.0
Operating system:   windows
Description:        

The following SQL has an unexpected syntax error

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

The AS clause is usually used to indicate alias, but it does not work in
this case

```
postgres=#
postgres=# SELECT version();
                          version
------------------------------------------------------------
 PostgreSQL 14.0, compiled by Visual C++ build 1914, 64-bit
(1 row)


postgres=# SELECT DISTINCT ON (col) AS col, col2 FROM test;
ERROR:  syntax error at or near "AS"
LINE 1: SELECT DISTINCT ON (col) AS col, col2 FROM test;
```



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #17232: DISTINCT ON does not allow AS
  2021-10-15 22:41 BUG #17232: DISTINCT ON does not allow AS PG Bug reporting form <noreply@postgresql.org>
@ 2021-10-15 23:01 ` David G. Johnston <david.g.johnston@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: David G. Johnston @ 2021-10-15 23:01 UTC (permalink / raw)
  To: kyle@lahnakoski.com <kyle@lahnakoski.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

On Friday, October 15, 2021, PG Bug reporting form <noreply@postgresql.org>
wrote:

> The following bug has been logged on the website:
>
> Bug reference:      17232
> Logged by:          Kyle Lahnakoski
> Email address:      kyle@lahnakoski.com
> PostgreSQL version: 14.0
> Operating system:   windows
> Description:
>
> The following SQL has an unexpected syntax error
>
>     SELECT DISTINCT ON (col) AS col, col2 FROM test
>
> The AS clause is usually used to indicate alias, but it does not work in
> this case
>

No it doesn’t.  Why do you think it should?  The columns in the ON parens
are not output so they don’t ned aliases.

David J.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #17232: DISTINCT ON does not allow AS
  2021-10-15 22:41 BUG #17232: DISTINCT ON does not allow AS PG Bug reporting form <noreply@postgresql.org>
@ 2021-10-16 14:59 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Alvaro Herrera @ 2021-10-16 14:59 UTC (permalink / raw)
  To: kyle@lahnakoski.com; pgsql-bugs@lists.postgresql.org

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)





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2021-10-16 14:59 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15 22:41 BUG #17232: DISTINCT ON does not allow AS PG Bug reporting form <noreply@postgresql.org>
2021-10-15 23:01 ` David G. Johnston <david.g.johnston@gmail.com>
2021-10-16 14:59 ` Alvaro Herrera <alvherre@alvh.no-ip.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox