Re: Delete with subquery deleting all records

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: Delete with subquery deleting all records
Дата
Msg-id 46554E8F.3050401@magproductions.nl
обсуждение исходный текст
Ответ на Delete with subquery deleting all records  (Francisco Reyes <lists@stringsutils.com>)
Список pgsql-general
Francisco Reyes wrote:
> When I try to run:
> delete from export_messages where export_id in
> (SELECT distinct export_messages.export_id as id
> FROM export_messages
> LEFT OUTER JOIN exports ON (export_messages.export_id = exports.export_id)
> );

Why not use EXISTS?

DELETE FROM export_messages WHERE NOT EXISTS (
    SELECT 1
      FROM exports
     WHERE exports.export_id = export_messages.export_id
)

I suppose you run those queries in a transaction block, right?

--
Alban Hertroys
alban@magproductions.nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
   7500 AK Enschede

// Integrate Your World //

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

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: OIDs - file objects, are damaged by PostgreSQL.
Следующее
От: Philippe Amelant
Дата:
Сообщение: Re: Tsearch2: upgrading from postgres 8.1.x to 8.2.x