Re: DELETE using an outer join

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
Cc: Thomas Kellerer <spam_eater(at)gmx(dot)net>, pgsql-sql(at)postgresql(dot)org
Subject: Re: DELETE using an outer join
Date: 2012-07-20 13:51:15
Message-ID: 16160.1342792275@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Sergey Konoplev <gray(dot)ru(at)gmail(dot)com> writes:
> On Thu, Jul 19, 2012 at 6:52 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> Now I was wondering if a DELETE statement could be rewritten with the same "strategy":

>> Not at the moment. There have been discussions of allowing the same
>> table name to be respecified in USING, but there are complications.

> However it works.

> DELETE FROM some_table USING some_table AS s
> WHERE
> some_table.col1 = s.col1 AND
> some_table.col2 = s.col2 AND
> some_table.id < s.id;

No, that's a self-join, which isn't what the OP wanted. You can make it
work if you self-join on the primary key and then left join to the other
table, but that's pretty klugy and inefficient.

What was being discussed is allowing people to write directly

DELETE FROM some_table USING some_table LEFT JOIN other_table ...

where the respecification of the table in USING would be understood
to mean the target table. Right now this is an error case because
of duplicate table aliases.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Sergey Konoplev 2012-07-20 14:13:31 Re: DELETE using an outer join
Previous Message Sergey Konoplev 2012-07-20 10:47:03 Re: DELETE using an outer join