Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-sql by date

Next:From: Stephan SzaboDate: 2003-02-28 20:34:45
Subject: Re: DELETE FROM t WHERE EXISTS
Previous:From: Jeff EckermannDate: 2003-02-28 19:30:56
Subject: Re: DELETE FROM t WHERE EXISTS

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group