pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: chester c young <chestercyoung@yahoo.com>
To: Neal Lindsay <neal.lindsay@peaofohio.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Inheritence and Integrity
Date: Wed, 29 Jan 2003 22:27:07 -0800 (PST)
Message-ID: <20030130062707.48883.qmail@web12703.mail.yahoo.com> (raw)
In-Reply-To: <b19bkt$5t9$1@news.hub.org>

> 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 ) that
 a) sets pk of table_name using master sequence
 b) attaches base trigger procedures onto 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 columns and 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



view thread (5+ messages)

Message-ID: <20030130062707.48883.qmail@web12703.mail.yahoo.com>
Permalink:  ../20030130062707.48883.qmail@web12703.mail.yahoo.com/
Also on:    postgresql.org/message-id/20030130062707.48883.qmail@web12703.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: chestercyoung@yahoo.com, neal.lindsay@peaofohio.com
  Subject: Re: Inheritence and Integrity
  In-Reply-To: <20030130062707.48883.qmail@web12703.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox