X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E2EDE475FBA for ; Fri, 28 Feb 2003 16:41:55 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 33504-10 for ; Fri, 28 Feb 2003 16:41:36 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 3FF91476069 for ; Fri, 28 Feb 2003 15:12:06 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id h1SKBr5u006000; Fri, 28 Feb 2003 15:11:53 -0500 (EST) To: "Dan Langille" Cc: pgsql-sql@postgresql.org Subject: Re: DELETE FROM t WHERE EXISTS In-reply-to: <3E5F530B.1649.424D34C1@localhost> References: <3E5F530B.1649.424D34C1@localhost> Comments: In-reply-to "Dan Langille" message dated "Fri, 28 Feb 2003 12:16:11 -0500" Date: Fri, 28 Feb 2003 15:11:53 -0500 Message-ID: <5999.1046463113@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new X-Archive-Number: 200302/621 X-Sequence-Number: 12019 "Dan Langille" writes: > So I tried this: > DELETE FROM clp > WHERE NOT EXISTS ( > SELECT * > FROM clp > ORDER BY commit_date > LIMIT 100); > Uhh uhh, nothing deleted. I don't understand why. Because the inner SELECT is a constant: you forgot to make it depend on the current outer row. So EXISTS succeeds at every row, unless clp is already empty. regards, tom lane