public inbox for [email protected]  
help / color / mirror / Atom feed
From: David Rowley <[email protected]>
To: PALAYRET Jacques <[email protected]>
Cc: [email protected]
Subject: Re: SQL ERROR subquery uses ungrouped column in PostgreSQL
Date: Thu, 1 May 2025 01:09:05 +1200
Message-ID: <CAApHDvpxHjkguu2zs3Fv2okrgvKzT27ao5CXfyVn7xhXc5HWLw@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

On Thu, 1 May 2025 at 00:29, PALAYRET Jacques <[email protected]> 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






reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: SQL ERROR subquery uses ungrouped column in PostgreSQL
  In-Reply-To: <CAApHDvpxHjkguu2zs3Fv2okrgvKzT27ao5CXfyVn7xhXc5HWLw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox