Re: group by can use alias from select list

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: postgres-hape(at)gmx(dot)de, pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: group by can use alias from select list
Date: 2023-07-11 14:19:48
Message-ID: 25b70e6ec7bef81acac508dc61dfa01e72c96252.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Fri, 2023-07-07 at 07:36 +0000, PG Doc comments form wrote:
> i have a discussion in pgsql-bugs(at)lists(dot)postgresql(dot)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

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message David G. Johnston 2023-07-11 14:31:26 Re: group by can use alias from select list
Previous Message PG Doc comments form 2023-07-07 07:36:00 group by can use alias from select list