Re: group by can use alias from select list

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, 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-09-06 23:51:34
Message-ID: ZPkQhuV8I6ijH+y3@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Tue, Jul 11, 2023 at 07:31:26AM -0700, David G. Johnston wrote:
> On Tue, Jul 11, 2023 at 7:19 AM Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> wrote:
>
> 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:
>
>
>
> I think the complaint is that someone seeing the behavior in the wild comes to
> this order-of-operations and doesn't see that the observed behavior is
> documented.  Sure, they can go into the GROUP BY section and figure out that
> there is a "oh, by the way" comment within there that output columns/aliases
> are indeed allowed.  But I tend to agree that a mention in the "order of
> operations" section that output columns from step 5 can be seen in step 4 seems
> like an improvement if we really want the order of operations to be the main
> reference entry point for people trying to work out query behavior.  Something
> like:  "(while unadvised it is possible for the aliases defined in the next
> step to be used here as well)".

How is the attached patch?

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

Only you can decide what is important to you.

Attachment Content-Type Size
group-by.diff text/x-diff 714 bytes

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2023-09-07 00:01:30 Re: group by can use alias from select list
Previous Message Laurenz Albe 2023-09-06 20:58:50 Re: to_char(numeric type, text) rounding instead of truncating