Re: Delete with join -- deleting related table entries? - Mailing list pgsql-sql

From Bryce Nesbitt
Subject Re: Delete with join -- deleting related table entries?
Date
Msg-id 43EA2D5D.6000304@obviously.com
Whole thread Raw
In response to Re: Delete with join -- deleting related table entries?  ("Owen Jacobson" <ojacobson@osl.com>)
Responses Re: Delete with join -- deleting related table entries?  (Markus Schaber <schabi@logix-tt.com>)
List 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 by date:

Previous
From: "BigSmoke"
Date:
Subject: Re: regarding debugging?
Next
From: Markus Schaber
Date:
Subject: Re: Delete with join -- deleting related table entries?