From: Markus Schaber <schabi@logix-tt.com>
To: pgsql-sql@postgresql.org
Cc: Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
Subject: Re: Foreign key reference counting strategy?
Date: Sat, 14 Oct 2006 15:52:04 +0200
Message-ID: <4530EB84.4050904@logix-tt.com> (raw)
In-Reply-To: <1160828741.28838.9.camel@panoramix>
References: <1160828741.28838.9.camel@panoramix>
Hi, Joost,
Joost Kraaijeveld wrote:
> Is there a strategy to implement reference counting for foreign keys so
> that if the last reference to the key is deleted, the record is deleted
> also?
Create an "after delete" trigger on the referencing table that checks
whether there still are records with the same key (IF EXISTS()), and
deletes the referenced row otherwise.
It won't hurt to have an index on the referencing column, for speed reasons.
HTH,
Markus
--
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf. | Software Development GIS
Fight against software patents in Europe! www.ffii.org
www.nosoftwarepatents.org
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: schabi@logix-tt.com, J.Kraaijeveld@Askesis.nl
Subject: Re: Foreign key reference counting strategy?
In-Reply-To: <4530EB84.4050904@logix-tt.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