pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christian Ullrich <chris@chrullrich.net>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #13336: Unexpected result from invalid query
Date: Sat, 23 May 2015 00:31:10 +0000
Message-ID: <AM2PR06MB0690F494EDEBCDF868475B66D4CF0@AM2PR06MB0690.eurprd06.prod.outlook.com> (raw)
In-Reply-To: <20150523001227.GA32396@alap3.anarazel.de>
References: <20150523000527.17709.45231@wrigleys.postgresql.org>
	<20150523001227.GA32396@alap3.anarazel.de>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

* From: Andres Freund [mailto:andres@anarazel.de]

> On 2015-05-23 00:05:27 +0000, chris@chrullrich.net wrote:
> > -- Note: No column "foo" in test_table2
> > postgres=# select * from test_table where foo in (select foo from
> > test_table2);
> >  foo | bar
> > -----+-----
> >  one |   1
> >  two |   2
> 
> That's not a bug. In a good number of subqueries you need access fields
> from the surrounding query.

Hm. That makes some sense, I guess. But is that true even if the reference in the subquery is not explicitly qualified? "SELECT foo FROM test_table2" looks to me like it refers to that table pretty unequivocally.

On the other hand I can find one sentence in the documentation on the subject, and it appears to support the conclusion that this is not a bug:

http://www.postgresql.org/docs/9.4/static/queries-table-expressions.html:

	Example: SELECT ... FROM fdt WHERE c1 IN (SELECT c3 FROM t2 WHERE c2 = fdt.c1 + 10)

	Qualifying c1 as fdt.c1 is only necessary if c1 is also the name of a 
	column in the derived input table of the subquery.

That can be read as confirming that resolving the unqualified name against the outer query is intended.

Still seems weird to me. But if that' the way it is, I'm sorry for the noise.

-- 
Christian



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (5+ messages)  latest in thread

Message-ID: <AM2PR06MB0690F494EDEBCDF868475B66D4CF0@AM2PR06MB0690.eurprd06.prod.outlook.com>
Permalink:  ../AM2PR06MB0690F494EDEBCDF868475B66D4CF0@AM2PR06MB0690.eurprd06.prod.outlook.com/
Also on:    postgresql.org/message-id/AM2PR06MB0690F494EDEBCDF868475B66D4CF0@AM2PR06MB0690.eurprd06.prod.outlook.com

 · 

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-bugs@postgresql.org
  Cc: chris@chrullrich.net, andres@anarazel.de
  Subject: Re: BUG #13336: Unexpected result from invalid query
  In-Reply-To: <AM2PR06MB0690F494EDEBCDF868475B66D4CF0@AM2PR06MB0690.eurprd06.prod.outlook.com>
  References: <20150523000527.17709.45231@wrigleys.postgresql.org> <20150523001227.GA32396@alap3.anarazel.de> <AM2PR06MB0690F494EDEBCDF868475B66D4CF0@AM2PR06MB0690.eurprd06.prod.outlook.com>

* 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