DELETE using an outer join

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема DELETE using an outer join
Дата
Msg-id ju8veb$dkn$1@dough.gmane.org
обсуждение исходный текст
Ответы Re: DELETE using an outer join  (Sergey Konoplev <sergey.konoplev@postgresql-consulting.com>)
Re: DELETE using an outer join  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
Hi,

(this is not a real world problem, just something I'm playing around with).

Lately I had some queries of the form:
   select t.*   from some_table t   where t.id not in (select some_id from some_other_table);

I could improve the performance of them drastically by changing the NOT NULL into an outer join:
   select t.*   from some_table t      left join some_other_table ot on ot.id = t.id   where ot.id is null;


Now I was wondering if a DELETE statement could be rewritten with the same "strategy":

Something like:
   delete from some_table   where id not in (select min(id)                     from some_table
groupby col1, col2                    having count(*) > 1);
 

(It's the usual - at least for me - "get rid of duplicates" statement)


The DELETE .. USING seems to only allow inner joins because it requires the join to be done in the WHERE clause.
So I can't think of a way to turn that NOT IN from the DELETE into an outer join with a derived table.

Am I right that this kind of transformation is not possible or am I missing something?

Regards
Thomas



В списке pgsql-sql по дате отправления:

Предыдущее
От: Puneet Mishra
Дата:
Сообщение: Order preservation of search phrases in postgresql FTS/OpenFTS
Следующее
От: Sergey Konoplev
Дата:
Сообщение: Re: DELETE using an outer join