Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 144F6475DFD for ; Tue, 26 Nov 2002 05:45:03 -0500 (EST) Received: from anchor-post-39.mail.demon.net (anchor-post-39.mail.demon.net [194.217.242.80]) by postgresql.org (Postfix) with ESMTP id A8E6D475D4B for ; Tue, 26 Nov 2002 05:45:01 -0500 (EST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-39.mail.demon.net with esmtp (Exim 3.36 #2) id 18GdDC-0006Xq-0U; Tue, 26 Nov 2002 10:45:03 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 232A917096; Tue, 26 Nov 2002 10:41:55 +0000 (GMT) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 4BC0017008; Tue, 26 Nov 2002 10:41:54 +0000 (GMT) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: patrick , pgsql-sql@postgresql.org Subject: Re: Are sub-select error suppressed? Date: Tue, 26 Nov 2002 10:41:50 +0000 User-Agent: KMail/1.4.3 References: <20021126014302.L3699@3eye.boxsoft.com> In-Reply-To: <20021126014302.L3699@3eye.boxsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200211261041.50766.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/363 X-Sequence-Number: 10505 On Tuesday 26 Nov 2002 9:43 am, patrick wrote: > Greetings, > > I'm not sure what the correct behavior is here but the observed > behavior seems "wrong" (or at least undesirable). > > I have a few tables and a view on one of the tables selecting > entries that may be purged. > > My delete statement uses the view to delete data from one of the > tables. Like so: > > delete from tab1 where id1 in ( select id from view1 ); > > Assume that the view doesn't have a field named "id". The select > statement alone would cause an error. However, in this context it > doesn't and the delete statement deletes everything from tab1. > > Is this a bug in PostgreSQL or an "As Designed" feature? Don't look right to me, and I still see it here in 7.2 and the 7.3 beta I'v= e=20 got (note - not most recent). I don't think it's in the subselect itself -= =20 what's happening is when you do DELETE FROM ttab_title_selection=20 WHERE tsel_id IN (SELECT xxx FROM tview_title); the xxx is binding to the outside query (the DELETE). If you change your=20 definition of ttab_title_selection to use tsel_id rather than title_id this= =20 will be clearer. You can get the same with ranking: DELETE FROM ttab_title_selection=20 WHERE ranking IN (SELECT ranking FROM tview_title); I'm guessing it gets parsed down to: DELETE FROM ttab_title_selection WHERE ranking IN (ranking); which of course matches everything. --=20 Richard Huxton