Re: [SQL] RE: Help with query. (*)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Diehl, Jeffrey" <jdiehl(at)sandia(dot)gov>
Cc: "'Ken Corey '" <ken(at)kencorey(dot)com>, "'pgsql-sql(at)postgresql(dot)org '" <pgsql-sql(at)postgresql(dot)org>, "'pgsql-general(at)postgresql(dot)org '" <pgsql-general(at)postgresql(dot)org>
Subject: Re: [SQL] RE: Help with query. (*)
Date: 2001-01-18 01:07:23
Message-ID: 22275.979780043@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

"Diehl, Jeffrey" <jdiehl(at)sandia(dot)gov> writes:
> Well, actually, I want to eventually delete the records from A if there is
> an entry in B. That's why I am trying to use such a screwed up query. ;^)

If you don't mind being nonstandard, you could still do it in join
style:

DELETE FROM a WHERE a.x = b.x AND blah blah blah ...

Under Postgres this will form a join between A and B same as if you'd
said SELECT FROM a,b WHERE a.x = b.x etc, and then delete the rows of
A that are matched in the join.

If you want to be bog-SQL-standard then you have to use the WHERE EXISTS
construct that Josh mentioned. Unfortunately, that's likely to be a
good deal slower (for large tables) under current releases of Postgres.
We have hopes of bringing the performance of the EXISTS variant up to
something close to the explicit join, but it's a version or two away
yet.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-01-18 01:11:50 Re: plperl and sqrt.
Previous Message Adam Haberlach 2001-01-18 01:06:01 More plpgsql fun! (deleting large object refs)

Browse pgsql-sql by date

  From Date Subject
Next Message Tubagus Nizomi 2001-01-18 01:28:38 Select 'Sunday' in month ??
Previous Message Keith Gray 2001-01-17 22:51:59 Re: Boolean and Bit