Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 87A019FB3A6 for ; Sat, 14 Oct 2006 10:52:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 50442-08 for ; Sat, 14 Oct 2006 13:52:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (mail.logix-tt.com [212.211.145.186]) by postgresql.org (Postfix) with ESMTP id 954B19FB399 for ; Sat, 14 Oct 2006 10:52:13 -0300 (ADT) Received: from kingfisher.intern.logix-tt.com (p549D1968.dip0.t-ipconnect.de [84.157.25.104]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id EDB6A657D3; Sat, 14 Oct 2006 15:54:37 +0200 (CEST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id ED4A7185A50FF; Sat, 14 Oct 2006 15:52:04 +0200 (CEST) Message-ID: <4530EB84.4050904@logix-tt.com> Date: Sat, 14 Oct 2006 15:52:04 +0200 From: Markus Schaber Reply-To: PostgreSQL SQL List Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Thunderbird 1.5.0.7 (X11/20060927) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Cc: Joost Kraaijeveld Subject: Re: Foreign key reference counting strategy? References: <1160828741.28838.9.camel@panoramix> In-Reply-To: <1160828741.28838.9.camel@panoramix> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.135 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200610/131 X-Sequence-Number: 26520 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