X-Original-To: pgsql-general@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 16878475B99 for ; Wed, 14 May 2003 20:08:02 -0400 (EDT) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with ESMTP id 73610-07 for ; Wed, 14 May 2003 20:08:00 -0400 (EDT) Received: from genie.gene.com (socks-open.gene.COM [192.12.78.1]) by postgresql.org (Postfix) with ESMTP id 5DB86474E4F for ; Wed, 14 May 2003 20:08:00 -0400 (EDT) Received: from zappa.gene.com (zappa.gene.com [128.137.1.70]) by genie.gene.com (8.12.9/8.12.8) with ESMTP id h4F07vMa305094 for ; Wed, 14 May 2003 17:07:57 -0700 (PDT) Received: from tallac.gene.com (tallac.gene.com [128.137.116.213]) by zappa.gene.com (8.11.0/8.11.0) with ESMTP id h4F07vE2138188 for ; Wed, 14 May 2003 17:07:57 -0700 (PDT) Subject: table inheritance and foreign keys From: Reece Hart To: pgsql-general@postgresql.org Content-Type: text/plain Organization: Genentech, Inc. Message-Id: <1052957276.5829.53.camel@tallac> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 14 May 2003 17:07:57 -0700 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/494 X-Sequence-Number: 42149 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