agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feed3 foreign keys in 1 table for 3 1-to-many relations?
2+ messages / 2 participants
[nested] [flat]
* 3 foreign keys in 1 table for 3 1-to-many relations?
@ 2015-06-18 00:51 gvim <gvimrc@gmail.com>
2015-06-18 01:30 ` Re: 3 foreign keys in 1 table for 3 1-to-many relations? David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: gvim @ 2015-06-18 00:51 UTC (permalink / raw)
To: pgsql-sql
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.
gvim
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: 3 foreign keys in 1 table for 3 1-to-many relations?
2015-06-18 00:51 3 foreign keys in 1 table for 3 1-to-many relations? gvim <gvimrc@gmail.com>
@ 2015-06-18 01:30 ` David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: David G. Johnston @ 2015-06-18 01:30 UTC (permalink / raw)
To: gvim <gvimrc@gmail.com>; +Cc: pgsql-sql
On Wed, Jun 17, 2015 at 8:51 PM, gvim <gvimrc@gmail.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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2015-06-18 01:30 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-06-18 00:51 3 foreign keys in 1 table for 3 1-to-many relations? gvim <gvimrc@gmail.com>
2015-06-18 01:30 ` David G. Johnston <david.g.johnston@gmail.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox