Re: REFERENCES constraint - Mailing list pgsql-sql

From Peter Eisentraut
Subject Re: REFERENCES constraint
Date
Msg-id Pine.LNX.4.30.0108122136370.714-100000@peter.localdomain
Whole thread Raw
In response to Re: REFERENCES constraint  (Cedar Cox <cedarc@visionforisrael.com>)
List pgsql-sql
Cedar Cox writes:

>   CREATE TABLE obj_weights (
>     object_id int4 REFERENCES ( apple_objects(id) OR banana_objects(id) )
>     weight float4,
>   )

The way I would work this out is like this:

CREATE TABLE fruit_objects ( object_id serial PRIMARY KEY, fruit_type text CHECK (fruit_type IN ('apple', 'banana')),
weightfloat4, ... other common fruit properties ...
 
);

CREATE TABLE apple_objects ( object_id integer REFERENCES fruit_objects, color text, ... more apple properties ...
);

CREATE TABLE banana_objects ( object_id integer REFERENCES fruit_objects, curvature real, ... other banana properties
...
);

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter



pgsql-sql by date:

Previous
From: Cedar Cox
Date:
Subject: Re: REFERENCES constraint
Next
From: "Josh Berkus"
Date:
Subject: Re: REFERENCES constraint