pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PALAYRET Jacques <jacques.palayret@meteo.fr>
To: PostgreSQL mailing lists <pgsql-general@postgresql.org>
Subject: Re: PostgreSQL : bug (ou not) in CTE Common Table Expressions or Subqueries in the FROM Clause
Date: Tue, 22 Mar 2022 16:03:17 +0100 (CET)
Message-ID: <1792999601.47365946.1647961397123.JavaMail.zimbra@meteo.fr> (raw)
In-Reply-To: <CAKFQuwZZHe4sjbUewdBnHcx+X2bYcLWQ_ws8GL1fM3+RnL+0AA@mail.gmail.com>
References: <1370619684.47054020.1647942355596.JavaMail.zimbra@meteo.fr>
	<CAKkG4_nQi6PWU3-rftkTr=8g3u5mB6QV9bFjODRNw2eXKrwOHg@mail.gmail.com>
	<812470944.47219637.1647953301941.JavaMail.zimbra@meteo.fr>
	<CAKFQuwZZHe4sjbUewdBnHcx+X2bYcLWQ_ws8GL1fM3+RnL+0AA@mail.gmail.com>


Constrained and forced, I am obliged to accept the behavior which is a means of using useful functionalities (standard SQL a priori). It's instructive for me. 

I don't know if it's the same behavior (more or less strict SQL 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: "David G. Johnston" <david.g.johnston@gmail.com> 
À: "PALAYRET Jacques" <jacques.palayret@meteo.fr> 
Cc: "PostgreSQL mailing lists" <pgsql-general@postgresql.org> 
Envoyé: Mardi 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 Jacques < [ mailto:jacques.palayret@meteo.fr | jacques.palayret@meteo.fr ] > wrote: 




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 ...) 
and it is : elev > 151 (correlation ou not correlation). 
In others words : for each line of table weather_stations), the only condition is : is the elev superior than the elev returned by the subquery, 151 ? 

Visibly, the correlated statement adds one condition ( [ http://w.id/ | w.id ] BETWEEN 31000000 and 31999999) in the main statement, but it's not logical for me, because of the parentheses. 



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’t isolate the subquery in the manner you ascribe to them, you’ll just need to adapt to reality. Its doesn’t 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. 

view thread (8+ messages)  latest in thread

Message-ID: <1792999601.47365946.1647961397123.JavaMail.zimbra@meteo.fr>
Permalink:  ../1792999601.47365946.1647961397123.JavaMail.zimbra@meteo.fr/
Also on:    postgresql.org/message-id/1792999601.47365946.1647961397123.JavaMail.zimbra@meteo.fr

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: jacques.palayret@meteo.fr
  Subject: Re: PostgreSQL : bug (ou not) in CTE Common Table Expressions or Subqueries in the FROM Clause
  In-Reply-To: <1792999601.47365946.1647961397123.JavaMail.zimbra@meteo.fr>
  References: <1370619684.47054020.1647942355596.JavaMail.zimbra@meteo.fr> <CAKkG4_nQi6PWU3-rftkTr=8g3u5mB6QV9bFjODRNw2eXKrwOHg@mail.gmail.com> <812470944.47219637.1647953301941.JavaMail.zimbra@meteo.fr> <CAKFQuwZZHe4sjbUewdBnHcx+X2bYcLWQ_ws8GL1fM3+RnL+0AA@mail.gmail.com> <1792999601.47365946.1647961397123.JavaMail.zimbra@meteo.fr>

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

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