Re: group by true now errors with non-integer constant in GROUP BY - Mailing list pgsql-bugs

From David Rowley
Subject Re: group by true now errors with non-integer constant in GROUP BY
Date
Msg-id CAApHDvomA1bZy=0AYUcTjDWaCeedcPeDBo6PV0VhpVeo2jG1uQ@mail.gmail.com
Whole thread Raw
In response to Re: group by true now errors with non-integer constant in GROUP BY  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: group by true now errors with non-integer constant in GROUP BY  (John Naylor <john.naylor@enterprisedb.com>)
List pgsql-bugs
On Tue, 29 Aug 2023 at 13:02, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> David Rowley <dgrowleyml@gmail.com> writes:
> > I had a look on dbfiddle and I see that MySQL 8.0 and SQLlite all
> > allow GROUP BY true.
>
> What do they do with GROUP BY 1, or GROUP BY 10000, or GROUP BY 1.0 ?

All treat only integer constants as column references.  Out-of-range
integer values are reported as errors.  Other const types appear to be
treated as expressions rather than column references.

> BTW, I poked around and couldn't find anything explaining this
> fine point in the SGML docs, although the comments in
> findTargetlistEntrySQL92 are clear about it.  If we do anything
> at all here, I think that ought to include documenting the behavior
> more clearly (and I'm curious to see how you'd propose to explain
> the behavior you want to users).

The rule and how to explain it seems fairly simple to me. Integer
constants are treated as column references to their corresponding
1-based position in the SELECT clause. Anything else is treated as an
expression.

David



pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: group by true now errors with non-integer constant in GROUP BY
Next
From: John Naylor
Date:
Subject: Re: group by true now errors with non-integer constant in GROUP BY