X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 6659E475E6F for ; Fri, 28 Feb 2003 17:17:54 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 43734-07 for ; Fri, 28 Feb 2003 17:17:43 -0500 (EST) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id 4A3D2474E42 for ; Fri, 28 Feb 2003 16:09:37 -0500 (EST) Received: by news.hub.org (Postfix, from userid 8) id 357B043A611; Fri, 28 Feb 2003 16:09:37 -0500 (EST) From: Dmitry Tkach X-Newsgroups: comp.databases.postgresql.sql Subject: Re: DELETE FROM t WHERE EXISTS Date: Fri, 28 Feb 2003 17:47:04 -0500 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 43 Message-ID: <3E5FE6E8.9020200@openratings.com> References: <3E5F530B.1649.424D34C1@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org To: Dan Langille User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en In-Reply-To: <3E5F530B.1649.424D34C1@localhost> To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new X-Archive-Number: 200302/626 X-Sequence-Number: 12024 What about select * into temp rows_to_keep from clp order by commit_date limit 100; truncate clp; insert into clp select * from rows_to_keep; Dima. Dan Langille wrote: > Hi folks, > > I wanted to delete "old" rows from a table. These are the rows I > want to keep: > > SELECT * > FROM clp > ORDER BY commit_date > LIMIT 100 > > 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. > > OK, I can do this instead: > > DELETE from clp > where commit_log_id NOT in ( > SELECT commit_log_id > FROM clp > ORDER BY commit_date > LIMIT 100); > > Can you think of a better way?