3

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

4
  • Your approach is correct - you need a parent location table. When exactly is this error appearing? Commented Oct 30, 2014 at 12:02
  • When I try to insert data in the event report table. Since the data is in the children tables, the dbms can't find the id referenced at the parent table Commented Oct 30, 2014 at 12:52
  • If you work with PostgreSQL's inheritance, this is known limitation postgresql.org/docs/current/static/… Commented Oct 30, 2014 at 12:58
  • Make a parent table without using the PostgreSQL's inheritance. Then you can refer to it from all the children and from the event report table as well. Commented Oct 30, 2014 at 13:51

1 Answer 1

1

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.

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

1 Comment

What does this look like from the OO modeling side of things? How are you defining/working with these models in your application?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.