Re: Foreign keys and inheritance

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Kynn Jones <kynnjo(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Foreign keys and inheritance
Date: 2007-11-19 21:57:51
Message-ID: 1195509471.22428.265.camel@dogma.ljc.laika.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 2007-11-19 at 17:19 -0300, Alvaro Herrera wrote:
> Kynn Jones escribió:
> > I have two classes of objects, A and B, where B is just a special case
> > of A. (I.e., to describe a B-type object I need to specify the same
> > fields as for an A-type object, plus a whole bunch additional fields
> > specific to B alone.) Furthermore, there's a third class T that is in
> > a many-to-one relation with A (and hence also B) objects.
> >
> > The question is, what's the "best practice" for implementing this
> > situation in PostgreSQL. My first idea was to define B as inheriting
> > from A, which is OK, except that I have not figured out how to
> > implement the reference from T. Is inheritance indeed the right tool
> > for this problem, or should I use a different approach?
>
> It would be the right tool if the FKs worked :-( Sadly, they don't.
>

I don't think it's that bad of a situation. It would be great if
PostgreSQL did support keys across tables, but it's not necessary for a
good design in his case.

The difference between using inheritance and just using multiple tables
(like the alternative that I suggested) is the difference between
vertically partitioning and horizontally partitioning. Both seem like
good choices to me.

Regards,
Jeff Davis

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Raymond O'Donnell 2007-11-19 22:05:06 Re: Postgre and XML
Previous Message Thomas Kellerer 2007-11-19 21:44:05 Re: Postgre and XML