Re: Inheritance and column references problem

From: Scott Goodwin <scott(at)scottg(dot)net>
To: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Inheritance and column references problem
Date: 2004-02-25 02:15:11
Message-ID: 70C2F3A3-6738-11D8-9C33-000A95A0910A@scottg.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I knew about child tables not getting the constraint for uniqueness --
I created a rule to do nothing on inserts to the parent table; all
inserts to the child tables had a before insert trigger that did a
select on the parent table to ensure the id I was about to insert was
truly unique. The inability for primary and foreign key constraints to
be inherited breaks what I wanted to do with it.

Still, in the first example I gave, the linkthem table had columns that
referenced the id from the parent table directly, not from the child
table that was inheriting the parent. What you're saying is that if I
insert directly into the parent table, the primary key will work, but
if I insert into the child table, the id will be 'visible' in the
parent, but won't be able to be referenced from a column in any other
table. Something for me to try -- I might still be able to inherit, but
then force all inserts of the primary key into the parent table
directly, with the rest of the fields being inserted into the child.

thanks for the info,

/s.

On Feb 24, 2004, at 7:38 PM, Stephan Szabo wrote:

>> Is this a bug, or a feature? It seems I can't make a column reference
>> work directly with the table that gets inherited by the others.
>> Neither
>> can I make a column reference work with a table that *inherits* the
>> toinherit table. If I can't get this to work, I'll have to revert back
>> to not using inheritance at all.
>
> All of primary key, unique and foreign key constraints don't currently
> meaningfully inherit. For the foreign key case the reference goes only
> to the directly named table so rows in the subtables are not considered
> for purposes of validating the constraint. In addition, in a structure
> where you have a primary key inherited, the child tables do not get the
> constraint for uniqueness although that can be added by explicitly
> putting
> the constraint on, however that won't prevent duplicates between the
> child
> and parent nor between children. There are some marginally complicated
> workarounds using a separate table that have been discussed on the
> lists
> before and should be available in the archives.
>
> I think I should build a macro for the above. ;)
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Holle 2004-02-25 02:36:49 Re: System tuning
Previous Message Joe Conway 2004-02-25 00:38:31 Re: select statement against pg_stats returns inconsistent