X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C1E319DC821 for ; Wed, 8 Feb 2006 13:41:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 00170-02 for ; Wed, 8 Feb 2006 13:41:57 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from outbound.internet-mail-service.net (outbound6.internet-mail-service.net [216.240.47.197]) by postgresql.org (Postfix) with ESMTP id C472C9DCC22 for ; Wed, 8 Feb 2006 13:41:56 -0400 (AST) Received: from idiom.com (idiom.com [216.240.32.1]) by outbound.internet-mail-service.net (Postfix) with ESMTP id 0183923FC5E for ; Wed, 8 Feb 2006 09:41:57 -0800 (PST) Received: from [192.168.1.109] (adsl-69-107-112-198.dsl.pltn13.pacbell.net [69.107.112.198]) by idiom.com (8.12.11/8.12.11) with ESMTP id k18Hfu7u048042 for ; Wed, 8 Feb 2006 09:41:56 -0800 (PST) (envelope-from bryce1@obviously.com) Message-ID: <43EA2D5D.6000304@obviously.com> Date: Wed, 08 Feb 2006 09:41:49 -0800 From: Bryce Nesbitt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050921 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Delete with join -- deleting related table entries? References: <144D12D7DD4EC04F99241498BB4EEDCC20CC56@nelson.osl.com> In-Reply-To: <144D12D7DD4EC04F99241498BB4EEDCC20CC56@nelson.osl.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.096 required=5 tests=[AWL=0.096] X-Spam-Score: 0.096 X-Spam-Level: X-Archive-Number: 200602/78 X-Sequence-Number: 24088 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 (as it'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_id from reservations where date > magic); DELETE FROM isuse WHERE reservation_id IN (select reservation_id from reservations where date > magic) DELETE FROM reservations WHERE reservation_id IN (select reservation_id from 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