On Fri, 2023-10-20 at 07:44 +0200, Vik Fearing wrote:
> > But according to my reading of the SQL standard, it only allows for
> > regular column references in GROUP BY. Unless I got something wrong,
> > that would mean the the ball is in Hibernate's court. It ought to
> > produce correct SQL.
>
> The answer is not as easy as that. It is true that the standard
> requires a <column reference> for each element of the GROUP BY clause,
> but it is also true that PostgreSQL allows arbitrary expressions.
>
> Why is this non-standard query allowed:
>
> vik=# select true group by true or true;
> ?column?
> ----------
> t
> (1 row)
>
>
> but not this one?
>
> vik=# select true group by true;
> ERROR: non-integer constant in GROUP BY
> LINE 1: select true group by true;
> ^
>
> I may have oversimplified this example, but as long as the value is
> present in the SELECT, logic would dictate that we can group by it.
I agree that it is desirable to fix this regression.
Still, we shouldn't exonerate Hibernate from fixing the junk SQL
it produces.
Yours,
Laurenz Albe