Re: Inheritence and Integrity - Mailing list pgsql-sql

From chester c young
Subject Re: Inheritence and Integrity
Date
Msg-id 20030130062707.48883.qmail@web12703.mail.yahoo.com
Whole thread Raw
In response to Inheritence and Integrity  (Neal Lindsay <neal.lindsay@peaofohio.com>)
List pgsql-sql
> inheriting pk and triggers

pg inheritance is quite limited.  what i (and i'm sure many others)
have done is:

1. create master sequence
2. create base table
3. create base trigger procedures
4. create derived tables, using "inherit"
5. write procedure p( table_name ) thata) sets pk of table_name using master sequenceb) attaches base trigger
proceduresonto table_name
 
6. run procedure p() against each derived table


another way to skin this cat is to use "objects" in the database:

-- base table
table common( int id primary key ..., ref_tab name,  -- name of secondary table using common ...            -- common
columnsand constraints
 
) without oids;

-- secondary table
table secondary1( int id1 not null references common(id), int id2 primary key,  -- (can use id1 as pk!) ...
     -- secondary columns and constraints
 
) without oids;

-- views for secondary table - generate!
create secondary1_v1 as select c.*, s.*
from secondary1 s join common c on( s.id1 = c.id );

-- (if you want) dml for view to make life easier - generate!
...

if you are maintaining the common info, or if you want a many to one
secondary to master, this approach is easier.


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com


pgsql-sql by date:

Previous
From: "Moritz Lennert"
Date:
Subject: Re: plpgsql: return results of a dynamic query
Next
From: Tony Simbine
Date:
Subject: Re: help: triggers