JSON foreign keys in PostgreSQL

后端 未结 3 2013
星月不相逢
星月不相逢 2021-02-12 13:15

Is it possible to assign a foreign key to a json property in PostgreSQL? Here is an example what I would like to achieve, but it doesn\'t work:

CREATE TABLE User         


        
3条回答
  •  心在旅途
    2021-02-12 13:49

    It is not possible, and may not ever be possible, to assign a foreign key to a json property. It'd be a major and quite complicated change to PostgreSQL's foreign key enforcement. I don't think it's impossible to do, but would face similar issues to those experienced by the foreign-keys-to-arrays patch.

    With 9.4 it'll be possible to make a whole json object a foreign key as jsonb supports equality tests. In 9.3 you can't even do that.

提交回复
热议问题