DELETE FROM t WHERE EXISTS

From: "Dan Langille" <dan(at)langille(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: DELETE FROM t WHERE EXISTS
Date: 2003-02-28 17:16:11
Message-ID: 3E5F530B.1649.424D34C1@localhost
Views: Raw Message | Whole Thread | Download mbox
Thread:
Lists: pgsql-sql

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?
--
Dan Langille : http://www.langille.org/

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Guy Fraser 2003-02-28 17:57:05 Re: WebDB, iAS
Previous Message Montrone, Marc -- 7183 2003-02-28 15:26:08 Optimizing