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.
-
SQL has no such concept itself. However, many ORMS add such mappings, as do OORDMBS. Looking at how, say, this is handled in both PostgreSQL and Hibernate may be beneficial.user166390– user1663902011年12月01日 23:57:45 +00:00Commented Dec 1, 2011 at 23:57
-
@Matthew Cox, Sorry I don't think so, multiple inheritance allows one to inherit from multiple tables, yes? What I need is for PersonBase to exists multiple times in PersonD, in other words say we have John Dow, what I would need is for John Dow to be able to exists more than once in PersonD, that if I search for John Dow(ID 5) it might possibly return two entries from PersonD. Sorry I should probably rephrase the question a bit :)Heinrich– Heinrich2011年12月02日 00:02:34 +00:00Commented Dec 2, 2011 at 0:02
-
This seems to me like duplicating rows? If they were all in one table John D. would exists in two rows?Damir Sudarevic– Damir Sudarevic2011年12月02日 12:26:51 +00:00Commented Dec 2, 2011 at 12:26
2 Answers 2
postgresql has actual table inheritance just like OOP. A Base table columns are inherited by "sub-tables" it also supports even multiple base classes.
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.