Re: Delete with join -- deleting related table entries?

Поиск
Список
Период
Сортировка
От Bryce Nesbitt
Тема Re: Delete with join -- deleting related table entries?
Дата
Msg-id 43EA2D5D.6000304@obviously.com
обсуждение исходный текст
Ответ на Re: Delete with join -- deleting related table entries?  ("Owen Jacobson" <ojacobson@osl.com>)
Ответы Re: Delete with join -- deleting related table entries?
Список pgsql-sql
Owen Jacobson wrote:
> BEGIN;
>   DELETE FROM note WHERE issue_id IN (SELECT issue_id FROM isuse
>     WHERE reservation_id = reservation_to_delete);
>   DELETE FROM isuse WHERE reservation_id = reservation_to_delete;
>   DELETE FROM reservations WHERE reservation_id = reservation_to_delete;
> COMMIT;
>
> With an appropriate value or expression substituted into reservation_to_delete.  This would be the "hard way", but
(asit's in a single transaction) will still protect other clients from seeing a partial delete.
 
Yup, that's exactly how I delete reservations one a time.   But here I
need to select a few thousand reservations, and I don't think this will
work:
BEGIN; DELETE FROM note WHERE issue_id IN (SELECT issue_id FROM isuse     WHERE reservation_id IN    (select
reservation_idfrom reservations where date > magic); DELETE FROM isuse WHERE reservation_id IN    (select
reservation_idfrom reservations where date > magic) DELETE FROM reservations WHERE reservation_id IN    (select
reservation_idfrom reservations where date > magic)
 
COMMIT;

I suppose I can do the subselect as a perl wrapper, but I was thinking
that maybe SQL could do it all for me....
                                 -Bryce



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

Предыдущее
От: "BigSmoke"
Дата:
Сообщение: Re: regarding debugging?
Следующее
От: Markus Schaber
Дата:
Сообщение: Re: Delete with join -- deleting related table entries?