Re: SQL ERROR subquery uses ungrouped column in PostgreSQL - Mailing list pgsql-general

From David Rowley
Subject Re: SQL ERROR subquery uses ungrouped column in PostgreSQL
Date
Msg-id CAApHDvpxHjkguu2zs3Fv2okrgvKzT27ao5CXfyVn7xhXc5HWLw@mail.gmail.com
Whole thread Raw
In response to SQL ERROR subquery uses ungrouped column in PostgreSQL  (PALAYRET Jacques <jacques.palayret@meteo.fr>)
List pgsql-general
On Thu, 1 May 2025 at 00:29, PALAYRET Jacques <jacques.palayret@meteo.fr> wrote:
> => In the subquery, the semantic analysis of the query considers the column " dat " instead of the expression "
to_char(dat,'yyyymm')", which is actually a grouped column.
 
> Is this normal? How can I simply resolve the problem?

Calculate the dat column in a subquery in the outer-level query.

Something like:

FROM (select *,to_char(dat, 'YYYYMM') as strdat from table1) table1
JOIN   table2   USING (num_poste)

then use strdat in all the places you're currently using to_char(dat, 'YYYYMM')

David



pgsql-general by date:

Previous
From: PALAYRET Jacques
Date:
Subject: SQL ERROR subquery uses ungrouped column in PostgreSQL
Next
From: Markus Demleitner
Date:
Subject: Index not used in certain nested views but not in others