0


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.

MikeMurko
2,2431 gold badge28 silver badges57 bronze badges
asked Dec 1, 2011 at 23:43
3
  • 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. Commented 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 :) Commented 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? Commented Dec 2, 2011 at 12:26

2 Answers 2

4

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

Eric Leschinski
155k96 gold badges422 silver badges337 bronze badges
answered Nov 1, 2012 at 22:57
0

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.

answered Dec 2, 2011 at 0:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.