pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Sergey Konoplev <gray.ru@gmail.com>
Cc: Thomas Kellerer <spam_eater@gmx.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: DELETE using an outer join
Date: Fri, 20 Jul 2012 09:51:15 -0400
Message-ID: <16160.1342792275@sss.pgh.pa.us> (raw)
In-Reply-To: <CAL_0b1shAZWP76=jpA47MLJE4p3q9_FHnAAy9ki_gXk1kVYJuQ@mail.gmail.com>
References: <ju8veb$dkn$1@dough.gmane.org>
	<21289.1342709554@sss.pgh.pa.us>
	<CAL_0b1shAZWP76=jpA47MLJE4p3q9_FHnAAy9ki_gXk1kVYJuQ@mail.gmail.com>

Sergey Konoplev <gray.ru@gmail.com> writes:
> On Thu, Jul 19, 2012 at 6:52 PM, Tom Lane <tgl@sss.pgh.pa.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



view thread (9+ messages)  latest in thread

Message-ID: <16160.1342792275@sss.pgh.pa.us>
Permalink:  ../16160.1342792275@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16160.1342792275@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, gray.ru@gmail.com, spam_eater@gmx.net
  Subject: Re: DELETE using an outer join
  In-Reply-To: <16160.1342792275@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox