Re: DELETE syntax on JOINS - Mailing list pgsql-hackers

From Tom Lane
Subject Re: DELETE syntax on JOINS
Date
Msg-id 15443.1251135688@sss.pgh.pa.us
Whole thread Raw
In response to Re: DELETE syntax on JOINS  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: DELETE syntax on JOINS  (Sam Mason <sam@samason.me.uk>)
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> 2009/8/24 Tom Lane <tgl@sss.pgh.pa.us>:
>> ... Some other systems
>> allow it by letting you re-specify the target in the other clause,
>> equivalently to
>> 
>> DELETE FROM target t USING t LEFT JOIN other_table ot ON ...
>> 
>> but we have always considered that the target is *not* to be identified
>> with any member of the FROM/USING clause, so it would be a serious
>> compatibility break to change that now.

> I'm all in favor of compatibility, but if there is any way to make
> this work without massive collateral damage, I am also all in favor of
> that.  I am forever writing queries that contain a needless self-join
> to work around the impossibility of directly outer-joining against the
> target.

It'd be pretty easy to do if we were willing to introduce a new reserved
word; for example

DELETE FROM target t USING SELF LEFT JOIN other_table ot ON ...

(or maybe TARGET instead of SELF, or some other word).  Wouldn't do
anything for exact compatibility with MySQL or anybody else using the
respecify-the-target-table-name approach.  But it would be unambiguous
and backwards-compatible.  The real problem with this is that all the
good candidates for the reserved word are things people are probably
already using as aliases, so we'd have a large risk of breaking existing
queries.  We could avoid that with a sufficiently ugly choice like

DELETE FROM target t USING DELETE_TARGET LEFT JOIN other_table ot ON ...

but yech ...
        regards, tom lane


pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: SIGUSR1 pingpong between master na autovacum launcher causes crash
Next
From: "Kevin Grittner"
Date:
Subject: Re: Slaying the HYPOTamus