X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 716299DC9BA for ; Tue, 7 Feb 2006 15:18:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23115-09 for ; Tue, 7 Feb 2006 15:18:08 -0400 (AST) X-Greylist: delayed 02:16:35.404577 by SQLgrey- Received: from ll.mit.edu (LLMAIL.LL.MIT.EDU [129.55.12.40]) by postgresql.org (Postfix) with ESMTP id E7ED69DC9B8 for ; Tue, 7 Feb 2006 15:18:05 -0400 (AST) Received: (from smtp@localhost) by ll.mit.edu (8.12.10/8.8.8) id k17JI6Al026407 for ; Tue, 7 Feb 2006 14:18:06 -0500 (EST) Received: from UNKNOWN( ), claiming to be "sty.llan" via SMTP by llmail, id smtpdAAABuaiOY; Tue Feb 7 14:17:51 2006 Date: Tue, 7 Feb 2006 14:17:51 -0500 From: george young To: pgsql-sql@postgresql.org Subject: Re: trecherous subselect needs warning? Message-Id: <20060207141751.38effa97.gry@ll.mit.edu> In-Reply-To: <27137.1139334353@sss.pgh.pa.us> References: <20060207120110.5d5f3c44.gry@ll.mit.edu> <27137.1139334353@sss.pgh.pa.us> Reply-To: gry@ll.mit.edu Organization: MIT Lincoln Laboratory X-Mailer: Sylpheed version 2.0.1 (GTK+ 2.8.0; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.061 required=5 tests=[AWL=0.060, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.061 X-Spam-Level: X-Archive-Number: 200602/69 X-Sequence-Number: 24079 On Tue, 07 Feb 2006 12:45:53 -0500 Tom Lane threw this fish to the penguins: > george young writes: > > This query returns zero rows: > > > newschm3=# select run_id from s_bake where opset_id not in (select opset_id from opset_steps); > > run_id > > -------- > > (0 rows) > > > But, by my mistake, table opset_steps has no column "opset_id"! > > Surely it should return an error, or at least a warning, not just an > > empty rowset. > > Access to upper-level variables from subqueries is (a) useful and (b) My orginal posting suggested a warning for the *useless* "from opset_steps" clause, since it's presence is misleading. But I don't suppose the SQL spec allows warnings that are not explicitly in the spec, alas. Of course upper-level variables must in general be accessible from subqueries. > required by the SQL spec, so we are not going to start throwing warnings > about it. I was just trying to find a way to prevent other innocent users from wasting many hours of torment tracking down this subtle twist of SQL... How about a *documentation* suggestion that sub-queries can be very dangerous if one doesn't qualify all column references? Maybe with an example like the one that bit me? -- George -- "Are the gods not just?" "Oh no, child. What would become of us if they were?" (CSL)