From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | Markus Bertheau <twanger(at)bluetwanger(dot)de>, PGSQL-SQL <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: multi-table unique index |
Date: | 2003-06-23 19:40:17 |
Message-ID: | 200306232040.18121.dev@archonet.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
foo/foo_1, then have a foreign key over both. The irritating thing is that
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_core
(foo_id, foo_type_id)
);
--
Richard Huxton
From | Date | Subject | |
---|---|---|---|
Next Message | Tomasz Myrta | 2003-06-23 22:04:42 | Re: aggregate question |
Previous Message | Markus Bertheau | 2003-06-23 19:08:37 | Re: multi-table unique index |