Skip site navigation (1) Skip section navigation (2)

Re: DELETE using an outer join

From: Sergey Konoplev <sergey(dot)konoplev(at)postgresql-consulting(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
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 14:13:31
Message-ID: CAL_0b1uDMQuYqpwTEr6JCd5AiwzevCEGJsGiM2DiMoJr_-p=sA@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-sql
On Fri, Jul 20, 2012 at 5:51 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> 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.

Yes, the OP has already pointed me to it. Thank you for your explanation.

-- 
Sergey Konoplev

a database architect, software developer at PostgreSQL-Consulting.com
http://www.postgresql-consulting.com

Jabber: gray(dot)ru(at)gmail(dot)com Skype: gray-hemp Phone: +79160686204

In response to

pgsql-sql by date

Next:From: ssyllaDate: 2012-07-23 03:04:32
Subject: query two tables using same lookup table
Previous:From: Tom LaneDate: 2012-07-20 13:51:15
Subject: Re: DELETE using an outer join

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group