pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dan Langille <dan@langille.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: DELETE FROM t WHERE EXISTS
Date: Fri, 28 Feb 2003 15:11:53 -0500
Message-ID: <5999.1046463113@sss.pgh.pa.us> (raw)
In-Reply-To: <3E5F530B.1649.424D34C1@localhost>
References: <3E5F530B.1649.424D34C1@localhost>

"Dan Langille" <dan@langille.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



view thread (11+ messages)  latest in thread

Message-ID: <5999.1046463113@sss.pgh.pa.us>
Permalink:  ../5999.1046463113@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5999.1046463113@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, dan@langille.org
  Subject: Re: DELETE FROM t WHERE EXISTS
  In-Reply-To: <5999.1046463113@sss.pgh.pa.us>

* 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