Re: DELETE FROM t WHERE EXISTS

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Dan Langille" <dan(at)langille(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: DELETE FROM t WHERE EXISTS
Date: 2003-02-28 20:11:53
Message-ID: 5999.1046463113@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Dan Langille" <dan(at)langille(dot)org> 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2003-02-28 20:34:45 Re: DELETE FROM t WHERE EXISTS
Previous Message Jeff Eckermann 2003-02-28 19:30:56 Re: DELETE FROM t WHERE EXISTS