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


From: Mark Roberts <mailing_lists(at)pandapocket(dot)com>
To: felix(at)crowfix(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: DELETE with JOIN
Date: 2008-08-07 20:27:00
Message-ID: 1218140820.28304.67.camel@localhost (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
On Thu, 2008-08-07 at 09:14 -0700, felix(at)crowfix(dot)com wrote:
>    DELETE FROM a WHERE a.b_id = AND b.second_id = ?

This should work for your needs:
delete from a
using b
where = -- join criteria
and b.second_id = ?

> I have tried to do this before and always found a way, usually
>     DELETE FROM a WHERE a.b_id IN (SELECT id FROM b WHERE second_id
> = ?)

This is akin to:
delete from a
where (a.key1, a.key2, a.key3) in (select key1, key2, key3 from b)

I use this every day for millions of rows per delete and it works just
fine and in a very reasonable time period.


In response to

pgsql-sql by date

Next:From: felixDate: 2008-08-07 21:35:46
Subject: Re: DELETE with JOIN
Previous:From: Frank BaxDate: 2008-08-07 20:01:29
Subject: Re: DELETE with JOIN

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