Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id C8FAA476313; Mon, 10 Jun 2002 17:52:22 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 3AE9A4769C6; Mon, 10 Jun 2002 17:09:25 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g5AL7ub08809; Mon, 10 Jun 2002 17:07:56 -0400 (EDT) To: Manfred Koizar Cc: Christoph Haller , pgsql-sql@postgresql.org, pgsql-hackers@postgresql.org Subject: Re: Efficient DELETE Strategies In-reply-to: References: <200206101142.NAA16854@rodos> <5619.1023717387@sss.pgh.pa.us> Comments: In-reply-to Manfred Koizar message dated "Mon, 10 Jun 2002 22:23:38 +0200" Date: Mon, 10 Jun 2002 17:07:56 -0400 Message-ID: <8806.1023743276@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200206/122 X-Sequence-Number: 8087 Manfred Koizar writes: >> If so, what's their syntax? > MSSQL seems to guess what the user wants. Gack. Nothing like treating mindless syntax variations as a "feature" list... > All the following statements do the same: > (1) DELETE t1 FROM t2 WHERE t1.i=t2.i > (2a) DELETE t1 FROM t2, t1 WHERE t1.i=t2.i > (5) DELETE t1 FROM t1 a > WHERE EXISTS (SELECT * FROM t2 WHERE a.i=t2.i) > (6) DELETE a FROM t1 a WHERE EXISTS (SELECT * FROM t2 WHERE a.i=t2.i) So in other words, MSSQL has no idea whether the name following DELETE is a real table name or an alias, and it's also unclear whether the name appears in the separate FROM clause or generates a FROM-item all by itself. This is why they have to punt on these cases: > These don't work: > DELETE t1 FROM t1 b WHERE 2 * b.i = t1.i > "The column prefix 't1' does not match with a table name or alias name > used in the query." > DELETE t1 FROM t1 a, t1 b WHERE 2 * b.i = a.i > "The table 't1' is ambiguous." The ambiguity is entirely self-inflicted... > And as if there aren't enough ways yet, I just discovered that (1) to > (6) just as much work with "DELETE FROM" where I wrote "DELETE" ... Hm. So (1) with the DELETE FROM corresponds exactly to what I was suggesting: DELETE FROM t1 FROM t2 WHERE t1.i=t2.i except that I'd also allow an alias in there: DELETE FROM t1 a FROM t2 b WHERE a.i=b.i Given the plethora of mutually incompatible interpretations that MSSQL evidently supports, though, I fear we can't use it as precedent for making any choices :-(. Can anyone check out other systems? regards, tom lane