Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 87B6E635BC8 for ; Wed, 3 Mar 2010 11:19:39 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 36945-01-4 for ; Wed, 3 Mar 2010 15:19:28 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sargon.lncsa.com (mail.lncsa.com [213.215.28.11]) by mail.postgresql.org (Postfix) with ESMTP id 45249635716 for ; Wed, 3 Mar 2010 11:19:06 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by sargon.lncsa.com (Postfix) with ESMTP id 9D15A301E6E2 for ; Wed, 3 Mar 2010 16:19:01 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at lncsa.com Received: from sargon.lncsa.com ([127.0.0.1]) by localhost (sargon.lncsa.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yLram2QhCizc for ; Wed, 3 Mar 2010 16:19:01 +0100 (CET) Received: from zenon.apartia.fr (zenon.apartia.fr [10.0.3.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "zenon.apartia.fr", Issuer "ca.apartia.fr" (verified OK)) by sargon.lncsa.com (Postfix) with ESMTP id 7E835300E01C for ; Wed, 3 Mar 2010 16:19:01 +0100 (CET) Received: from galba.apartia.fr (galba.apartia.fr [10.0.3.119]) by zenon.apartia.fr (Postfix) with ESMTP id 2875A58A0DA2B for ; Wed, 3 Mar 2010 16:19:01 +0100 (CET) Received: by galba.apartia.fr (Postfix, from userid 1000) id 115961D42C; Wed, 3 Mar 2010 16:19:00 +0100 (CET) Date: Wed, 3 Mar 2010 16:19:00 +0100 From: Louis-David Mitterrand To: pgsql-sql@postgresql.org Subject: Re: check constraint on multiple tables? Message-ID: <20100303151900.GA19735@apartia.fr> Mail-Followup-To: pgsql-sql@postgresql.org References: <20100303150227.GA18661@apartia.fr> <396486431003030714s48b239e2ub8b58a49b9aa29e4@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <396486431003030714s48b239e2ub8b58a49b9aa29e4@mail.gmail.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201003/14 X-Sequence-Number: 33721 On Wed, Mar 03, 2010 at 07:14:29AM -0800, Richard Broersma wrote: > On Wed, Mar 3, 2010 at 7:02 AM, Louis-David Mitterrand > wrote: > > > > What is the best solution? Adding an id_ship to 'cabin'? Or check'ing > > with a join down to 'ship'? (if possible). > > Can you post simplified table definitions for the relations involved? Sure, here they are: CREATE TABLE ship ( id_ship serial primary key, ship_name text unique not null ); CREATE TABLE cabin_type ( id_cabin_type serial primary key, id_ship integer references ship, cabin_type_name text, cabin_type_code text, unique(cabin_type_code, id_ship) ); CREATE TABLE cabin_category ( id_cabin_category serial primary key, id_cabin_type integer references cabin_type, cabin_cat_name text, cabin_cat_code text, unique(cabin_cat_code, id_cabin_type) ); CREATE TABLE cabin ( id_cabin serial primary key, id_cabin_category integer references cabin_category, cabin_number integer not null, unique(id_cabin_category, cabin_number) );