skip to Main Content

I’ve looked across a lot of Q&As for this, but haven’t found any real answers, so I made this question.

A lot of tech companies don’t actually use foreign keys. Whether it be for easier migrations, or performance improvements, that’s what those companies decided on.

However foreign keys provide very useful self documentation of a database. Up until now, I’ve relied on this feature from DataGrip:
https://www.jetbrains.com/help/datagrip/virtual-foreign-keys.html

My ask: is there a way to get "virtual foreign keys" in postgres? It seems silly that such an ability doesn’t exist natively, considering how many companies don’t use foreign keys.

Edit: No idea why people downvoted this question because it doesn’t follow their philosophies. Whether you or your circles use or don’t use foreign keys, to each their own. Downvoting the question due to something like that is quite childish.

Here is some educational information to show that large tech companies do not use foreign keys: https://github.com/github/gh-ost/issues/331#issuecomment-266027731

2

Answers


  1. No, there is no such feature. At best, you can use comments:

    COMMENT ON COLUMN mytab.mycol IS 'This should reference tab.pkey';
    

    I cannot help mentioning that you seem to be living on a different plane than I do. I have been looking at many people’s data designs in my professional career, and only a small minority use the misguided performance optimization of omitting foreign keys.

    You do without foreign keys in a data warehouse, because they would make loading too painful, and consistency is provided by your transactional database. A transactional database must have foreign keys.

    Login or Signup to reply.
  2. As most professionals know, most tech companies don’t actually use
    foreign keys.

    Call me an amateur, but I do use them. And most databases using Oracle, DB2, SQL Server, PostgreSQL, etc. also use them. Maybe just the amateurs like me, that’s up to you to decide.

    A virtual key is just some comment in an XML file in DataGrip. Works nice for documentation, but has no added value in the database itself.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search