Re: deleting referenced data

From: Richard Huxton <dev(at)archonet(dot)com>
To: Bruno Wolff III <bruno(at)wolff(dot)to>
Cc: Andreas Fromm <Andreas(dot)Fromm(at)physik(dot)uni-erlangen(dot)de>, pgsql-general(at)postgresql(dot)org
Subject: Re: deleting referenced data
Date: 2003-08-26 18:25:17
Message-ID: 200308261925.17518.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tuesday 26 August 2003 18:55, Bruno Wolff III wrote:
> On Tue, Aug 26, 2003 at 18:34:04 +0100,
>
> Richard Huxton <dev(at)archonet(dot)com> wrote:
> > On Tuesday 26 August 2003 15:06, Andreas Fromm wrote:
> > > When I delete a record of the table realtions I also want to delete the
> > > record on the data-tables if there is no other record referencing them.
> > > How can I do this?
> >
> > You want to add "ON DELETE CASCADE" to the REFERENCES... clause.
> > See the SQL reference for full syntax details.
>
> I don't think that is what he wants. He seems to want to go in the other
> direction. That is going to require custom triggers and probably adding a
> reference count column to data-tables.

Ah - you're quite right Bruno. That's the approach I'd take. Andreas - take
care with simultaneous adding/removal in the relations table - that could
lead to an unexpected failure unless you make sure you're using serializable
transaction level.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Maksim Likharev 2003-08-26 18:27:36 Re: Linux ready for high-volume databases?
Previous Message Jonathan Bartlett 2003-08-26 18:20:05 Re: Bulk Insert / Update / Delete