On Fri, 2023-07-07 at 07:36 +0000, PG Doc comments form wrote: > i have a discussion in pgsql-b...@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