pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dmitry Tkach <dmitry@openratings.com>
To: Dan Langille <dan@langille.org>
Subject: Re: DELETE FROM  t WHERE EXISTS
Date: Fri, 28 Feb 2003 17:47:04 -0500
Message-ID: <3E5FE6E8.9020200@openratings.com> (raw)
In-Reply-To: <3E5F530B.1649.424D34C1@localhost>
References: <3E5F530B.1649.424D34C1@localhost>

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?




view thread (11+ messages)

Message-ID: <3E5FE6E8.9020200@openratings.com>
Permalink:  ../3E5FE6E8.9020200@openratings.com/
Also on:    postgresql.org/message-id/3E5FE6E8.9020200@openratings.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dmitry@openratings.com, dan@langille.org
  Subject: Re: DELETE FROM  t WHERE EXISTS
  In-Reply-To: <3E5FE6E8.9020200@openratings.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox