pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bryce Nesbitt <bryce1@obviously.com>
To: pgsql-sql@postgresql.org
Subject: Re: Delete with join -- deleting related table entries?
Date: Wed, 08 Feb 2006 09:41:49 -0800
Message-ID: <43EA2D5D.6000304@obviously.com> (raw)
In-Reply-To: <144D12D7DD4EC04F99241498BB4EEDCC20CC56@nelson.osl.com>
References: <144D12D7DD4EC04F99241498BB4EEDCC20CC56@nelson.osl.com>

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




view thread (10+ messages)  latest in thread

Message-ID: <43EA2D5D.6000304@obviously.com>
Permalink:  ../43EA2D5D.6000304@obviously.com/
Also on:    postgresql.org/message-id/43EA2D5D.6000304@obviously.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bryce1@obviously.com
  Subject: Re: Delete with join -- deleting related table entries?
  In-Reply-To: <43EA2D5D.6000304@obviously.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox