Heinrich
Heinrich

Reputation: 2214

Database Table Inheritance


Is it possible for a table to inherit on-to-many sub tables? (I think thats how its meant to be worded :P) In others words:

 PersonBase can be PersonA and/or PersonD and/or PersonC

However in this particular case it needs to be possible for PersonBase to exist multiple times as PersonD (there are reasons for it), could I do it this way? Or should I create another table say TableD such that PersonBase is a PersonD which has a one to many relationship with TableD. However I would prefer to be able to do it so that PersonBase can be multiple PersonDs if possible.

Thanks All

P.S. I apologize if my question seems naive.

Upvotes: 0

Views: 367

Answers (2)

jk121960
jk121960

Reputation: 873

postgresql has actual table inheritance just like OOP. A Base table columns are inherited by "sub-tables" it also supports even multiple base classes.

Upvotes: 4

ypercubeᵀᴹ
ypercubeᵀᴹ

Reputation: 115510

I think what you describe in the first case, between PersonBase (supertype) and PersonA, PersonC (subtype), are 1:1 relationships (supertype/subtype), while in the second case, between PersonBase and PersonD, is a 1:n relationship.

Upvotes: 0

Related Questions