I was wondering if there is a good way to model one to many relationships with postgres 9.6 (i.e. have an array of foreign keys). I know its doable via junction tables but I'm wondering if there's a simpler solution (like creating a custom trigger/constraint in postgres). Thanks!
2 Answers
Sounds like you want to reference many tables from a single row. Something like this will do it.
CREATE TABLE a( columnA integer references B(columnName) , columnB integer references C(columnName) , columnC integer references D(columnName) , etc....... ); In my opinion something like this is asking for a headache.
Comments
Having a variety of foreign keys is not a problem. This is part of the entity-relationship model and its normal forms.
N-N relationship entities should only be used in many-to-many cases.
If your table has many foreign keys, the logical model of your data must be verified, it may be poorly modeled.
create tablestatements for the tables in question and a description on how exactly you want to define those foreign keys. Formatted text please, no screen shots