From: Reece Hart <rkh@gene.COM>
To: pgsql-general@postgresql.org
Subject: table inheritance and foreign keys
Date: 14 May 2003 17:07:57 -0700
Message-ID: <1052957276.5829.53.camel@tallac> (raw)
I'd appreciate some advice regarding the use of foreign keys in
inherited tables. Specifically, here's the schema I'd like:
A S
-------- --------
id serial pkey <---1:1---> id integer references A(id)
name text +-/
|
A1 |
-------- |
(inherits A) <--1:1-+
id serial
C1 text
This doesn't work because the foreign key constraint can only bind to
one table. In other words, I'd like S.id to reference the union of id
keys from A and A1. This is analogous to the union select generated by
'select ... from A'.
Is there a way to achieve the same end by a different design (with
reasonable effort)? The best I can think of is to make A1 a distinct
table joinable on id, and then create a view with insert rule which
separately inserts into A and A1.
I've used table inheritance extensively and find it quite useful.
Extending the OO abstraction to a table's indices would enable even more
concise and expressive designs.
Thanks,
Reece
--
Reece Hart, Ph.D. rkh@gene.com, http://www.gene.com/
Genentech, Inc. 650/225-6133 (voice), -5389 (fax)
Bioinformatics and Protein Engineering
1 DNA Way, MS-93 http://www.in-machina.com/~reece/
South San Francisco, CA 94080-4990 reece@in-machina.com, GPG: 0x25EC91A0
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: rkh@gene.COM
Subject: Re: table inheritance and foreign keys
In-Reply-To: <1052957276.5829.53.camel@tallac>
References: <1052957276.5829.53.camel@tallac>
* 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