Re: Foreign keys/unique values and views

From: "Richard Huxton" <dev(at)archonet(dot)com>
To: "Einar Karttunen" <ekarttun(at)cs(dot)Helsinki(dot)FI>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Foreign keys/unique values and views
Date: 2001-03-22 17:12:59
Message-ID: 001f01c0b2f3$6a3db580$1001a8c0@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

From: "Einar Karttunen" <ekarttun(at)cs(dot)Helsinki(dot)FI>

> On Thu, 22 Mar 2001, Richard Huxton wrote:
> >
> > I have to admit I've never tried referencing a view with a foreign key.
I
> > don't know if it's possible and I have to admit the idea makes me
> > uncomfortable. Can't give a good reason why, but I'd apply constraints
at
> > the table level.
> if one can reference a table with a foreign key it makes possible to
> reference inheritance hierarchies. If I create a view from the parent
> with CREATE VIEW name SELECT * FROM parent; (in v.7.1) it should contain
> the entries from the children as well. Now if I could reference this view
> I could simulate referencing parent and child tables easily.
> What I have in mind is a hierarchy of persons all inheriting from a table
> called person. Different kinds of persons have different attributes but
> all have an id and name. What I want is that other tables could reference
> these persons easily.

Ah - makes sense. I must admit I don't use inheritence/arrays since I never
know what platform I'll end up running on, so I like to keep things to
standard SQL where possible.

Trying the obvious (reference an id field in the parent) fails on execution:
referential integrity violation - key referenced from bar not found in
foo_parent

You also can't reference the id field in the child table.

There's a question on this on the pgsql-sql list (from Johannes Groden -
dated today) but I don't see any replies yet. This sounds like something
Tom/Bruce will need to get involved in.

- Richard Huxton

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jonas Bengtsson 2001-03-22 17:17:27 RE: OID as Primary Key
Previous Message Marko Kreen 2001-03-22 17:12:39 Re: Call for platforms