ebarbara
ebarbara

Reputation: 165

PostgreSQL - Foreign Key referencing multiple tables

I've got this problem at a postgres database. I have four tables of location data (hospitals, schools, markets and police precints), slightly different between themselves, and a event report table that has a location column, referencing a location.

How can I make this reference, to a id that can be in any of the location tables? I've tried to reference a parent table of them all, but inserts return an error of "key not present at table"

Thanks

Upvotes: 3

Views: 2162

Answers (1)

ebarbara
ebarbara

Reputation: 165

Per Kouber Saparev's suggestion, I've removed the inheritance and used foreign keys to reference the parent from the children. It's working perfectly now.

Upvotes: 1

Related Questions