Re: help with "delete joins" - Mailing list pgsql-sql

From Josh Berkus
Subject Re: help with "delete joins"
Date
Msg-id 200306301735.29482.josh@agliodbs.com
Whole thread Raw
In response to help with "delete joins"  (Robert Treat <rtreat@webmd.net>)
Responses Re: help with "delete joins"  (Robert Treat <xzilla@users.sourceforge.net>)
List 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 barWHERE bar.a = foo.a AND bar.b = foo.b    AND bar.c = foo.c );


--
-Josh BerkusAglio Database SolutionsSan Francisco



pgsql-sql by date:

Previous
From: Rudi Starcevic
Date:
Subject: Re: Bitwise operation
Next
From: Rod Taylor
Date:
Subject: Re: cleaning up useless pl/pgsql functions