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 3154830F673 for ; Mon, 23 Jun 2003 17:33:15 +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 20356-08 for ; Mon, 23 Jun 2003 14:33:04 -0300 (ADT) Received: from dbdevel.sunwave.net (h64-141-16-15.sunwave.net [64.141.16.15]) by svr1.postgresql.org (Postfix) with ESMTP id 8491B30F615 for ; Mon, 23 Jun 2003 14:33:04 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by dbdevel.sunwave.net (Postfix) with ESMTP id 77D7A178008; Mon, 23 Jun 2003 13:32:56 -0400 (EDT) From: Michael A Nachbaur To: Markus Bertheau , PGSQL-SQL Subject: Re: multi-table unique index Date: Mon, 23 Jun 2003 10:32:56 -0700 User-Agent: KMail/1.5 References: <1056376700.2037.2.camel@fluor> In-Reply-To: <1056376700.2037.2.camel@fluor> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200306231032.56257.mike@nachbaur.com> X-Archive-Number: 200306/269 X-Sequence-Number: 14027 Instead of using the "serial" datatype, you can set it to "int4 PRIMARY KEY DEFAULT nextval(foo_type_id_seq)" and you can manually create the sequence "foo_type_id_seq". This way all the tables share the same sequence. On Monday 23 June 2003 06:58 am, 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 > ); > > -- 2nd special foo: > > create table foo_2 ( > foo_2_id serial primary key, > foo_id int not null references foo, > foo_2_data1 numeric(8,2), > foo_2_data2 timestamp > ); > > -- And I have bars that each have zero or more (special) foos. > > create table bar ( > bar_id serial primary key > ); > > create table bar_foos ( > bar_id int not null references bar, > foo_id int not null references foo > ); > > -- Now how do I prevent that I can insert a foo_1 and a foo_2 with > -- the same foo_id? Or is the design errorneous itself? > > -- > Markus Bertheau > Berlin, Berlin, Germany > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) -- Michael A Nachbaur