Re: Foreign keys to inherited tables

From: brian <brian(at)zijn-digital(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Foreign keys to inherited tables
Date: 2008-03-20 03:42:35
Message-ID: 47E1DD2B.70207@zijn-digital.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Leon Mergen wrote:
> Hello,
>
> I was wondering, I'm reading that there is no support for foreign keys
> to inherited (child) tables -- are there any plans on supporting these
> in the (near) future, and/or are there any practical workarounds for
> this ?
>

This has worked well for me:

CREATE TABLE child_table (
...
) INHERITS (parent_table);

ALTER TABLE child_table ALTER COLUMN id SET DEFAULT
nextval('parent_table_id_seq');

CREATE UNIQUE INDEX child_table_pk ON child_table (id);

Note that it's not necessary to declare an id column for the child.

b

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Brent Wood 2008-03-20 03:51:57 Postgres development
Previous Message - Edwin - 2008-03-20 03:29:21 Re: Which JDBC version to use with PostgreSQL 8.1.11?