Connecting Tech Pros Worldwide Forums | Help | Site Map

Inheritance and foreign keys

Brendan Jurd
Guest
 
Posts: n/a
#1: Nov 12 '05
Hi all,

I read on the manual page for Inheritance that:

"A limitation of the inheritance feature is that indexes (including
unique constraints) and foreign key constraints only apply to single
tables, not to their inheritance children. Thus, in the above example,
specifying that another table's column REFERENCES cities(name) would
allow the other table to contain city names but not capital names. This
deficiency will probably be fixed in some future release."

I have a few projects that could benefit from inherited table structure,
and it's a very cool idea, but this inability of indexes to include
derived tables is a real functionality-killer. It's not "Object
Relational" if the objects can't be related to anything!

If someone could give me an idea of how far away this fix is, I'd be
grateful.

Cheers

BJ


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Peter Eisentraut
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Inheritance and foreign keys


Brendan Jurd wrote:[color=blue]
> I have a few projects that could benefit from inherited table
> structure, and it's a very cool idea, but this inability of indexes
> to include derived tables is a real functionality-killer. It's not
> "Object Relational" if the objects can't be related to anything![/color]

Hehe, but the "relational" means that the data is stored in relations,
not that the data has to be related to other data.
[color=blue]
> If someone could give me an idea of how far away this fix is, I'd be
> grateful.[/color]

No one has really expressed intentions to fix this, so I wouldn't hold
my breath.


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Stephan Szabo
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Inheritance and foreign keys


On Tue, 9 Dec 2003, Brendan Jurd wrote:
[color=blue]
> Hi all,
>
> I read on the manual page for Inheritance that:
>
> "A limitation of the inheritance feature is that indexes (including
> unique constraints) and foreign key constraints only apply to single
> tables, not to their inheritance children. Thus, in the above example,
> specifying that another table's column REFERENCES cities(name) would
> allow the other table to contain city names but not capital names. This
> deficiency will probably be fixed in some future release."
>
> I have a few projects that could benefit from inherited table structure,
> and it's a very cool idea, but this inability of indexes to include
> derived tables is a real functionality-killer. It's not "Object
> Relational" if the objects can't be related to anything!
>
> If someone could give me an idea of how far away this fix is, I'd be
> grateful.[/color]

I'd say at least 1, probably more versions out. Unique constraints across
an inheritance tree are pretty much a requirement for inherited foreign
keys and I'm not planning to even start thinking about the foreign key
side until after unique's done.

As a note, there are workarounds for foreign keys that have been mentioned
in the past. I'm not really sure anyone's post a real good workaround for
unique though.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Stephan Szabo
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Inheritance and foreign keys


On Mon, 8 Dec 2003, Stephan Szabo wrote:
[color=blue]
> On Tue, 9 Dec 2003, Brendan Jurd wrote:
>[color=green]
> > Hi all,
> >
> > I read on the manual page for Inheritance that:
> >
> > "A limitation of the inheritance feature is that indexes (including
> > unique constraints) and foreign key constraints only apply to single
> > tables, not to their inheritance children. Thus, in the above example,
> > specifying that another table's column REFERENCES cities(name) would
> > allow the other table to contain city names but not capital names. This
> > deficiency will probably be fixed in some future release."
> >
> > I have a few projects that could benefit from inherited table structure,
> > and it's a very cool idea, but this inability of indexes to include
> > derived tables is a real functionality-killer. It's not "Object
> > Relational" if the objects can't be related to anything!
> >
> > If someone could give me an idea of how far away this fix is, I'd be
> > grateful.[/color]
>
> I'd say at least 1, probably more versions out. Unique constraints across[/color]

Errm, that was supposed to say "at least 2," given the absense of a good
plan.

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Jan Wieck
Guest
 
Posts: n/a
#5: Nov 12 '05

re: Inheritance and foreign keys


Stephan Szabo wrote:[color=blue]
> On Tue, 9 Dec 2003, Brendan Jurd wrote:
>[color=green]
>> Hi all,
>>
>> I read on the manual page for Inheritance that:
>>
>> "A limitation of the inheritance feature is that indexes (including
>> unique constraints) and foreign key constraints only apply to single
>> tables, not to their inheritance children. Thus, in the above example,
>> specifying that another table's column REFERENCES cities(name) would
>> allow the other table to contain city names but not capital names. This
>> deficiency will probably be fixed in some future release."
>>
>> I have a few projects that could benefit from inherited table structure,
>> and it's a very cool idea, but this inability of indexes to include
>> derived tables is a real functionality-killer. It's not "Object
>> Relational" if the objects can't be related to anything!
>>
>> If someone could give me an idea of how far away this fix is, I'd be
>> grateful.[/color]
>
> I'd say at least 1, probably more versions out. Unique constraints across
> an inheritance tree are pretty much a requirement for inherited foreign
> keys and I'm not planning to even start thinking about the foreign key
> side until after unique's done.
>
> As a note, there are workarounds for foreign keys that have been mentioned
> in the past. I'm not really sure anyone's post a real good workaround for
> unique though.[/color]

Wouldn't a central table just holding the unique key values and
maintained by rules/triggers from all the tables in the inheritance tree
do the trick?

That central table would be the referenced one too then, because it
contains the union of all keys.

It would not inherit automagically, but if set up manually that way it
would act correct.


Jan

--
#================================================= =====================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================= = JanWieck@Yahoo.com #


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Stephan Szabo
Guest
 
Posts: n/a
#6: Nov 12 '05

re: Inheritance and foreign keys


On Tue, 9 Dec 2003, Jan Wieck wrote:
[color=blue]
> Stephan Szabo wrote:[color=green]
> > On Tue, 9 Dec 2003, Brendan Jurd wrote:
> >
> > As a note, there are workarounds for foreign keys that have been mentioned
> > in the past. I'm not really sure anyone's post a real good workaround for
> > unique though.[/color]
>
> Wouldn't a central table just holding the unique key values and
> maintained by rules/triggers from all the tables in the inheritance tree
> do the trick?
>
> That central table would be the referenced one too then, because it
> contains the union of all keys.[/color]

That's the general thing for the fks and I guess the insert into the
central table should have the correct behavior in concurrent calls as
well.


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Jan Wieck
Guest
 
Posts: n/a
#7: Nov 12 '05

re: Inheritance and foreign keys


Stephan Szabo wrote:
[color=blue]
> On Tue, 9 Dec 2003, Jan Wieck wrote:
>[color=green]
>> Stephan Szabo wrote:[color=darkred]
>> > On Tue, 9 Dec 2003, Brendan Jurd wrote:
>> >
>> > As a note, there are workarounds for foreign keys that have been mentioned
>> > in the past. I'm not really sure anyone's post a real good workaround for
>> > unique though.[/color]
>>
>> Wouldn't a central table just holding the unique key values and
>> maintained by rules/triggers from all the tables in the inheritance tree
>> do the trick?
>>
>> That central table would be the referenced one too then, because it
>> contains the union of all keys.[/color]
>
> That's the general thing for the fks and I guess the insert into the
> central table should have the correct behavior in concurrent calls as
> well.[/color]

I'm not 100% sure though. Is there any possibility that an entry in a
table hides an entry in an inherited one?


Jan

--
#================================================= =====================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================= = JanWieck@Yahoo.com #


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Closed Thread