Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nWg2f-0006Jv-MC for pgsql-general@arkaria.postgresql.org; Tue, 22 Mar 2022 15:03:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nWg2e-0000AL-Ft for pgsql-general@arkaria.postgresql.org; Tue, 22 Mar 2022 15:03:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nWg2e-0000AB-4N for pgsql-general@lists.postgresql.org; Tue, 22 Mar 2022 15:03:24 +0000 Received: from smtp-zimbra.meteo.fr ([137.129.16.22] helo=celebrian1.meteo.fr) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nWg2a-0007bt-4L for pgsql-general@postgresql.org; Tue, 22 Mar 2022 15:03:23 +0000 Received: from localhost (localhost [127.0.0.1]) by celebrian1.meteo.fr (Postfix) with ESMTP id 5F9381C2198 for ; Tue, 22 Mar 2022 16:03:18 +0100 (CET) Received: from celebrian1.meteo.fr ([127.0.0.1]) by localhost (celebrian1.meteo.fr [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 4TAFfa5koT0i for ; Tue, 22 Mar 2022 16:03:18 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by celebrian1.meteo.fr (Postfix) with ESMTP id 41C721C21A5 for ; Tue, 22 Mar 2022 16:03:18 +0100 (CET) X-Virus-Scanned: amavisd-new at celebrian1.meteo.fr Received: from celebrian1.meteo.fr ([127.0.0.1]) by localhost (celebrian1.meteo.fr [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id gDNQHYg9E2q7 for ; Tue, 22 Mar 2022 16:03:18 +0100 (CET) Received: from zumba5.meteo.fr (zumba5 [172.31.9.201]) by celebrian1.meteo.fr (Postfix) with ESMTP id 258381C2198 for ; Tue, 22 Mar 2022 16:03:18 +0100 (CET) Date: Tue, 22 Mar 2022 16:03:17 +0100 (CET) From: PALAYRET Jacques To: PostgreSQL mailing lists Message-ID: <1792999601.47365946.1647961397123.JavaMail.zimbra@meteo.fr> In-Reply-To: References: <1370619684.47054020.1647942355596.JavaMail.zimbra@meteo.fr> <812470944.47219637.1647953301941.JavaMail.zimbra@meteo.fr> Subject: Re: PostgreSQL : bug (ou not) in CTE Common Table Expressions or Subqueries in the FROM Clause MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_73e3fa57-9527-4f2c-af30-53427642bc92" X-Originating-IP: [172.31.9.205] X-Mailer: Zimbra 8.7.11_GA_3822 (ZimbraWebClient - FF91 (Win)/8.7.11_GA_3822) Thread-Topic: PostgreSQL : bug (ou not) in CTE Common Table Expressions or Subqueries in the FROM Clause Thread-Index: 2odKuCR4OTcHnr4xM5iwnuFv3snifw== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=_73e3fa57-9527-4f2c-af30-53427642bc92 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Constrained and forced, I am obliged to accept the behavior which is a mean= s of using useful functionalities (standard SQL a priori). It's instructive= for me.=20 I don't know if it's the same behavior (more or less strict SQL standard) i= n other DBMS.=20 For example, in Oracle it is not possible to have a SELECT statement withou= t a FROM clause (using DUAL table), so maybe " ambiguous " columns are not = handled in the same way.=20 Anyway, thank you very much for the explanation.=20 Regards=20 De: "David G. Johnston" =20 =C3=80: "PALAYRET Jacques" =20 Cc: "PostgreSQL mailing lists" =20 Envoy=C3=A9: Mardi 22 Mars 2022 14:04:32=20 Objet: Re: PostgreSQL : bug (ou not) in CTE Common Table Expressions or Sub= queries in the FROM Clause=20 On Tuesday, March 22, 2022, PALAYRET Jacques < [ mailto:jacques.palayret@me= teo.fr | jacques.palayret@meteo.fr ] > wrote:=20 According to me, there is only one condition in the main statement (SELECT = [ http://w.id/ | w.id ] , [ http://w.name/ | w.name ] , w.elev FROM weather= _stations ...)=20 and it is : elev > 151 (correlation ou not correlation).=20 In others words : for each line of table weather_stations), the only condit= ion is : is the elev superior than the elev returned by the subquery, 151 ?= =20 Visibly, the correlated statement adds one condition ( [ http://w.id/ | w.i= d ] BETWEEN 31000000 and 31999999) in the main statement, but it's not logi= cal for me, because of the parentheses.=20 I agree your example query is written poorly and thus is confusing. But it = is not possible for the system to distinguish a poorly written query from a= goodly written one that uses the same functionality. As the functionality = is useful, and the parentheses simply don=E2=80=99t isolate the subquery in= the manner you ascribe to them, you=E2=80=99ll just need to adapt to reali= ty. Its doesn=E2=80=99t have to seem logical to you, but this is how it is = defined to work and thus the observed behavior is not a bug.=20 David J.=20 --=_73e3fa57-9527-4f2c-af30-53427642bc92 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

Con= strained and forced, I am obliged to accept the behavior which is a means o= f using useful functionalities (standard SQL a priori). It's instructive fo= r me.

I don't know if it's the same behavior (more or less strict SQ= L standard) in other DBMS.
For example, in Oracle it is not possible to = have a SELECT statement without a FROM clause (using DUAL table), so maybe = " ambiguous " columns are not handled in the same way.

Anyway, thank= you very much for the explanation.
Regards

De: "Davi= d G. Johnston" <david.g.johnston@gmail.com>
=C3=80: "PALAYR= ET Jacques" <jacques.palayret@meteo.fr>
Cc: "PostgreSQL mai= ling lists" <pgsql-general@postgresql.org>
Envoy=C3=A9: Mar= di 22 Mars 2022 14:04:32
Objet: Re: PostgreSQL : bug (ou not) in = CTE Common Table Expressions or Subqueries in the FROM Clause

=
On Tuesday, March 22, 2022, PALAYRET J= acques <jacques.palayret@meteo.fr> wrote= :

A= ccording to me, there is only one condition in the main statement (SELECT <= a href=3D"http://w.id" target=3D"_blank" rel=3D"nofollow noopener noreferre= r">w.id, w.name, w.elev FROM weather_stations ...)
and it = is : elev > 151 (correlation ou not correlation).
In others words : f= or each line of table weather_stations), the only condition is : is the ele= v superior than the elev returned by the subquery, 151 ?

Visibly, th= e correlated statement adds one condition (w.id BETWEEN 31000000 = and 31999999) in the main statement, but it's not logical for me, because o= f the parentheses.

I agree your exam= ple query is written poorly and thus is confusing.  But it is not poss= ible for the system to distinguish a poorly written query from a goodly wri= tten one that uses the same functionality.  As the functionality is us= eful, and the parentheses simply don=E2=80=99t isolate the subquery in the = manner you ascribe to them, you=E2=80=99ll just need to adapt to reality.&n= bsp; Its doesn=E2=80=99t have to seem logical to you, but this is how it is= defined to work and thus the observed behavior is not a bug.

David J.

--=_73e3fa57-9527-4f2c-af30-53427642bc92--