Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uA6Yx-00Ak54-PG for pgsql-general@arkaria.postgresql.org; Wed, 30 Apr 2025 12:29:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uA6Yv-00DlH3-5I for pgsql-general@arkaria.postgresql.org; Wed, 30 Apr 2025 12:29:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uA6Yu-00DlGo-Oc for pgsql-general@lists.postgresql.org; Wed, 30 Apr 2025 12:29:17 +0000 Received: from zcsmtaf02-pub.meteo.fr ([137.129.63.6]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uA6Ys-000Lbu-0L for pgsql-general@lists.postgresql.org; Wed, 30 Apr 2025 12:29:16 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by zcsmtaf02-pub.meteo.fr (Postfix) with ESMTP id A695642711AC for ; Wed, 30 Apr 2025 12:29:11 +0000 (GMT) Received: from zcsmtaf02-pub.meteo.fr ([127.0.0.1]) by localhost (zcsmtaf02.meteo.fr [127.0.0.1]) (amavis, port 10032) with ESMTP id hiQ_xyvzX2nq for ; Wed, 30 Apr 2025 12:29:11 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcsmtaf02-pub.meteo.fr (Postfix) with ESMTP id 8DF9142893C1 for ; Wed, 30 Apr 2025 12:29:11 +0000 (GMT) X-Virus-Scanned: amavis at meteo.fr Received: from zcsmtaf02-pub.meteo.fr ([127.0.0.1]) by localhost (zcsmtaf02.meteo.fr [127.0.0.1]) (amavis, port 10026) with ESMTP id TI9dWpphl46f for ; Wed, 30 Apr 2025 12:29:11 +0000 (GMT) Received: from zcsmsm04.meteo.fr (zcsmsm04.meteo.fr [172.24.3.124]) by zcsmtaf02-pub.meteo.fr (Postfix) with ESMTP id 79FC342711AC for ; Wed, 30 Apr 2025 12:29:11 +0000 (GMT) Date: Wed, 30 Apr 2025 12:29:11 +0000 (GMT) From: PALAYRET Jacques To: pgsql-general@lists.postgresql.org Message-ID: <557588747.121401914.1746016151124.JavaMail.zimbra@meteo.fr> Subject: SQL ERROR subquery uses ungrouped column in PostgreSQL MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_0486f3e5-e9f2-4db7-9141-00854e3605ae" X-Originating-IP: [172.24.2.157] X-Mailer: Zimbra 9.0.0_GA_4583 (ZimbraWebClient - FF128 (Win)/9.0.0_GA_4583) Thread-Index: EDyJM6+/8SaEAMixJw/1cRgDSUK0Xg== Thread-Topic: SQL ERROR subquery uses ungrouped column in PostgreSQL List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=_0486f3e5-e9f2-4db7-9141-00854e3605ae Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hello, I have an unexpected error in my following query (of course, the query has been simplified here to request help): SELECT num_poste, to_char(dat, 'YYYYMM')::integer dat, CASE FLOOR((TO_NUMBER(TO_CHAR(dat,'DD'),'99')-1)/10) WHEN 0 THEN 1 WHEN 1 THEN 2 ELSE 3 END::smallint AS num_decade , CASE WHEN ( CASE FLOOR((TO_NUMBER(TO_CHAR(dat,'DD'),'99')-1)/10) WHEN 0 THEN 1 WHEN 1 THEN 2 ELSE 3 END::smallint IN (1 , 2) AND count(glot)=10 ) THEN ( SELECT valeur FROM table3 WHERE num_serie_coef=CASE WHEN num_poste <96000000 THEN 0 WHEN num_poste BETWEEN 97100000 and 98899999 THEN num_poste/100000 END AND coef = 'APRIME_ANGSTROM' AND num_mois=substr( to_char(dat,'yyyymm') , 5, 2)::smallint ) ELSE NULL END AS toto FROM table1 JOIN table2 USING (num_poste) GROUP BY num_poste, to_char(dat, 'YYYYMM') , CASE FLOOR((TO_NUMBER(TO_CHAR(dat,'DD'),'99')-1)/10) WHEN 0 THEN 1 WHEN 1 THEN 2 ELSE 3 END::smallint ORDER BY num_poste, to_char(dat, 'YYYYMM'), CASE FLOOR((TO_NUMBER(TO_CHAR(dat,'DD'),'99')-1)/10) WHEN 0 THEN 1 WHEN 1 THEN 2 ELSE 3 END::smallint ERROR : subquery uses ungrouped column "table1.dat" from outer query LIGNE 10 : AND num_mois=substr( to_char(dat,'yyyymm') , 5, 2)::smallint ^ => 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? Sincerely. --=_0486f3e5-e9f2-4db7-9141-00854e3605ae Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hello,

I have an unexpected erro= r in my following query (of course, the query has been simplified here to r= equest help):

SELECT num_poste, to_char(dat, 'YYYYMM')::integer dat,= CASE FLOOR((TO_NUMBER(TO_CHAR(dat,'DD'),'99')-1)/10) WHEN 0 THEN 1 WHEN 1 = THEN 2 ELSE 3 END::smallint AS num_decade
, CASE
WHEN (  CASE FL= OOR((TO_NUMBER(TO_CHAR(dat,'DD'),'99')-1)/10) WHEN 0 THEN 1 WHEN 1 THEN 2 E= LSE 3 END::smallint IN (1 , 2) AND count(glot)=3D10  )
THEN
(SELECT valeur
FROM table3
WHERE num_serie_coef=3DCASE WHEN num_post= e <96000000 THEN 0 WHEN num_poste BETWEEN 97100000 and 98899999 THEN num= _poste/100000 END
AND coef =3D 'APRIME_ANGSTROM'
AND num_mois=3Dsubs= tr(to_char(dat,'yyyymm'), 5, 2)::smallint
)
ELSE NUL= L
END AS toto
FROM  table1   JOIN   table2&n= bsp;  USING (num_poste)
GROUP BY num_poste, to_char(dat, 'YYYYMM'), CASE FLOOR((TO_NUMBER(TO_CHAR(dat,'DD'),= '99')-1)/10) WHEN 0 THEN 1 WHEN 1 THEN 2 ELSE 3 END::smallint
ORDER BY n= um_poste, to_char(dat, 'YYYYMM'), CASE FLOOR((TO_NUMBER(TO_CHAR(dat,'DD'),'= 99')-1)/10) WHEN 0 THEN 1 WHEN 1 THEN 2 ELSE 3 END::smallint

ERRORsubque= ry uses ungrouped column "table1.dat" from outer query
LIGNE 10 : AND num_mois=3Dsubstr(to_char(dat= ,'yyyymm'), 5, 2)::smallint
  = ;            &n= bsp;            = ;            ^

=3D> In the subquery, the semantic analysis of the query consid= ers the column " dat " instead of the expression " to_char(dat= ,'yyyymm') ", which is actually a grouped column.
Is this normal? H= ow can I simply resolve the problem?

Sincerely.
--=_0486f3e5-e9f2-4db7-9141-00854e3605ae--