X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 787F630F527 for ; Mon, 23 Jun 2003 19:40:33 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 38232-02 for ; Mon, 23 Jun 2003 16:40:23 -0300 (ADT) Received: from anchor-post-30.mail.demon.net (anchor-post-30.mail.demon.net [194.217.242.88]) by svr1.postgresql.org (Postfix) with ESMTP id A64F930F640 for ; Mon, 23 Jun 2003 16:40:22 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-30.mail.demon.net with esmtp (Exim 3.35 #1) id 19UXAs-000CYp-0U; Mon, 23 Jun 2003 20:40:23 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id C4D6517CB5; Mon, 23 Jun 2003 20:40:21 +0100 (BST) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 2B53217CB3; Mon, 23 Jun 2003 20:40:21 +0100 (BST) Content-Type: text/plain; charset="utf-8" From: Richard Huxton Organization: Archonet Ltd To: Markus Bertheau , PGSQL-SQL Subject: Re: multi-table unique index Date: Mon, 23 Jun 2003 20:40:17 +0100 User-Agent: KMail/1.4.3 References: <1056376700.2037.2.camel@fluor> In-Reply-To: <1056376700.2037.2.camel@fluor> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200306232040.18121.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Archive-Number: 200306/274 X-Sequence-Number: 14032 On Monday 23 Jun 2003 2:58 pm, Markus Bertheau wrote: > -- Suppose I have several types of foos > > create table foo_types ( > foo_type_id serial primary key, > foo_name text not null > ); > > -- And the foos itself: > > create table foo ( > foo_id serial primary key, > foo_type_id int not null references foo_types, > foo_general_data1 text > ); > > -- 1st special foo: > > create table foo_1 ( > foo_1_id serial primary key, > foo_id int not null references foo, > foo_1_data1 int, > foo_1_data2 text > ); An alternative to Markus' ideas in the other thread - store the type in=20 foo/foo_1, then have a foreign key over both. The irritating thing is that= =20 you're duplicating the type info unnecessarily. CREATE TABLE foo ( foo_id serial unique, foo_type_id int not null references foo_types, ... PRIMARY KEY (foo_id,foo_type_id) ); CREATE TABLE foo_1 ( extra_foo int4 not null, extra_type int4 not null extra1 text, PRIMARY KEY (extra_foo, extra_type) CONSTRAINT link_to_foo FOREIGN KEY (extra_foo,extra_type) REFERENCES foo_c= ore=20 (foo_id, foo_type_id) ); --=20 Richard Huxton