Re: group by can use alias from select list - Mailing list pgsql-docs

From Laurenz Albe
Subject Re: group by can use alias from select list
Date
Msg-id 25b70e6ec7bef81acac508dc61dfa01e72c96252.camel@cybertec.at
Whole thread Raw
In response to group by can use alias from select list  (PG Doc comments form <noreply@postgresql.org>)
Responses Re: group by can use alias from select list
List pgsql-docs
On Fri, 2023-07-07 at 07:36 +0000, PG Doc comments form wrote:
> i have a discussion in pgsql-bugs@lists.postgresql.org about this and it is
> mentioned in the answers that it is documented and a "feature" of Postgres
> that this can be done.
> If this is wanted the documentation
> (https://www.postgresql.org/docs/current/sql-select.html) that mentioned:
> [execution order of SELECT that says that GROUP BY is before SELECT]
> isn't correct because how  can 4.) be done and the alias from 5.) is used?
> Here is a hint important that there is an exception for alias used in group
> by

I think that is already documented:

> An expression used inside a grouping_element can be an input column name,
> or the name or ordinal number of an output column (SELECT list item),
> or an arbitrary expression formed from input-column values.

An alias in this case would be an output column.  Perhaps we can mention
the alias explicitly.

Yours,
Laurenz Albe



pgsql-docs by date:

Previous
From: PG Doc comments form
Date:
Subject: group by can use alias from select list
Next
From: "David G. Johnston"
Date:
Subject: Re: group by can use alias from select list