Re: inherited columns as foreign keys WAS "no subject"

From: Michael Adler <adler(at)glimpser(dot)org>
To: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: inherited columns as foreign keys WAS "no subject"
Date: 2002-04-06 15:27:37
Message-ID: Pine.NEB.4.44.0204060842490.6472-100000@reva.sixgirls.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Fri, 5 Apr 2002, Stephan Szabo wrote:

> > I get a "referential integrity violation", but the referenced key *does*
> > exist in the referenced table.
> >
> > I don't think that it's important, but the table "object" is inherited by
> > other tables.
>
> In fact it may certainly be... References constraints do not inherit
> to children currently. The constraint selects from only the named table
> (do a select * from ONLY object where id=...) and I'd guess that the row
> is actually in one of the children.

I think the solution is to create a unique index on the child
table so that you can reference the inherited column.

In that "gee, it would be nice" category of suggestions, I'd like to see
more documentation on inheritance, it's limitations and suggested
workarounds. This has probably all been said before..

The interactive docs on inheritance suggest one workaround for inherited
columns as foreign keys: use a "CHECK" constraint with a custom function
instead of REFERENCES constraint. Without much investigation, it seems
like a better idea to create a unique index on the child table and
REFERENCE that. This seems simpler to setup and affords more integrity
features. I haven't really tried it, though.

The other limitation that I didn't find in the main docs is that child
tables don't inherit triggers. You have to add a trigger for each child
table, although I was able to reuse the same function.

It would be great to have this info in one place in the docs.

I feel like including the obvious: PostgreSQL is spectacular. I can't
imagine using anything else in this problem space.

Mike Adler

In response to

  • Re: at 2002-04-05 22:34:50 from Stephan Szabo

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Command Prompt, Inc. 2002-04-06 17:39:26 Re: Who's using PostgreSQL?
Previous Message Devrim GUNDUZ 2002-04-06 12:40:20 Who's using PostgreSQL?