| From: | Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> |
|---|---|
| To: | Josh Berkus <josh(at)agliodbs(dot)com>, Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: help with "delete joins" |
| Date: | 2003-07-01 13:43:07 |
| Message-ID: | 1057066987.24310.383.camel@camel |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On Mon, 2003-06-30 at 20:35, Josh Berkus wrote:
> 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.
the end of a long day that started with 4 hours of sleep... no wonder I
couldn't get my head around this one. I actually did want the results of
the psuedo query, not the results I posted :-\
> 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 );
I was almost there with my original query... a NOT on your/stephan's
query gets me what I really want. :-) Thanks guys.
Robert Treat
--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Rod Taylor | 2003-07-01 13:53:08 | Re: CREATE SEQUENCE fails in plpgsql function |
| Previous Message | Tom Lane | 2003-07-01 13:33:53 | Re: CREATE SEQUENCE fails in plpgsql function |