Re: SQL ERROR subquery uses ungrouped column in PostgreSQL

Поиск
Список
Период
Сортировка
От David Rowley
Тема Re: SQL ERROR subquery uses ungrouped column in PostgreSQL
Дата
Msg-id CAApHDvpxHjkguu2zs3Fv2okrgvKzT27ao5CXfyVn7xhXc5HWLw@mail.gmail.com
обсуждение исходный текст
Ответ на SQL ERROR subquery uses ungrouped column in PostgreSQL  (PALAYRET Jacques <jacques.palayret@meteo.fr>)
Список 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 по дате отправления: