1

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!

4
  • What do you want to achieve? Commented Jul 11, 2017 at 14:05
  • I want to have a single row in a table be able to reference multiple rows in foreign tables Commented Jul 11, 2017 at 14:06
  • 4
    Add FK to the other table... Commented Jul 11, 2017 at 14:07
  • Please Edit your question and add the create table statements for the tables in question and a description on how exactly you want to define those foreign keys. Formatted text please, no screen shots Commented Jul 11, 2017 at 14:28

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

-1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.