Re: help with "delete joins"

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Robert Treat <rtreat(at)webmd(dot)net>, pgsql-sql(at)postgresql(dot)org
Subject: Re: help with "delete joins"
Date: 2003-07-01 00:35:29
Message-ID: 200306301735.29482.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Robert,

> delete * from foo where not (foo.a = bar.a and foo.b=bar.b and
> foo.c=bar.c) ;
>
> so i end up with
>
> postgres=# select * from foo;
> a | b | c | d
> ---+---+---+---
> 1 | 2 | 4 | A
> 4 | 5 | 6 | b
> (2 rows)
>
> but thats not valid sql, is there some way to accomplish this?

Um, your example result doesn't match your pseudo-query. Assuming that you
want to delete everything that DOES match, not everything that DOESN'T, do:

DELETE FROM foo
WHERE EXISTS ( SELECT bar.a FROM bar
WHERE bar.a = foo.a AND bar.b = foo.b
AND bar.c = foo.c );

--
-Josh Berkus
Aglio Database Solutions
San Francisco

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Rod Taylor 2003-07-01 00:39:06 Re: cleaning up useless pl/pgsql functions
Previous Message Rudi Starcevic 2003-06-30 23:48:01 Re: Bitwise operation