Re: 3 foreign keys in 1 table for 3 1-to-many relations?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: gvim <gvimrc(at)gmail(dot)com>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: 3 foreign keys in 1 table for 3 1-to-many relations?
Date: 2015-06-18 01:30:11
Message-ID: CAKFQuwbnXfCnGWh5MatiY3QEkC5c86+VLXfdPRFyqrOXrqCq8A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Jun 17, 2015 at 8:51 PM, gvim <gvimrc(at)gmail(dot)com> wrote:

> I have 3 tables A, B & C each of which has a 1-to-many relation with a
> Comments table but I can't fathom how to set up the foreign key(s) in
> Comments without resorting to distinct A_id, B_id & C_id columns in
> Comments and enforcing 2 of the 3 columns be NULL for a given row. Seems
> ugly.

You should probably take a look at inheritance and see if it can
accommodate your use case.

http://www.postgresql.org/docs/9.4/static/tutorial-inheritance.html

David J​

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Marc Mamin 2015-06-18 19:45:37 Re: self join issue
Previous Message gvim 2015-06-18 00:51:43 3 foreign keys in 1 table for 3 1-to-many relations?