X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 346619FA69A for ; Mon, 24 Jul 2006 18:16:56 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 68020-08 for ; Mon, 24 Jul 2006 18:16:51 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from wolff.to (wolff.to [66.93.197.194]) by postgresql.org (Postfix) with SMTP id 9726B9FA666 for ; Mon, 24 Jul 2006 18:16:51 -0300 (ADT) Received: (qmail 21755 invoked by uid 500); 24 Jul 2006 21:22:36 -0000 Date: Mon, 24 Jul 2006 16:22:36 -0500 From: Bruno Wolff III To: Richard Jones Cc: pgsql-sql@postgresql.org Subject: Re: Referential integrity (foreign keys) across multiple tables Message-ID: <20060724212236.GA14923@wolff.to> Mail-Followup-To: Bruno Wolff III , Richard Jones , pgsql-sql@postgresql.org References: <20060722133257.GA9785@furbychan.cocan.org> <20060723183237.GA22586@wolff.to> <20060724085907.GA19981@furbychan.cocan.org> <20060724175148.GA25994@wolff.to> <20060724175320.GA18434@furbychan.cocan.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060724175320.GA18434@furbychan.cocan.org> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.017 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200607/304 X-Sequence-Number: 25878 On Mon, Jul 24, 2006 at 18:53:20 +0100, Richard Jones wrote: > > I'm not sure what this means. By "data integrity" I just meant that I > don't want applications to create page_contents.link_name fields which > could point to non-existent URLs. (A URL consists of a particular > hostid and url, since you're not allowed to have one host pointing to > pages on another, and this is where the requirement for a foreign key > which spans two tables comes from). Perhaps I meant "data > consistency"? Anyway without some sort of check, be it a reference or > a trigger -- assuming a trigger is possible -- then an application > might create such a bad link. I think part of the problem might have been over simplification of the problem. In your example there was no reason to create that new column since the information was available by doing a join between two tables and this would prevent a problem with data being out of sync. I see from another message in this thread that there is really more to this example. It may be that you still don't need the new column, but I haven't examined the new example carefully to say one way or the other.