JSON foreign keys in PostgreSQL

后端 未结 3 2005
星月不相逢
星月不相逢 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:32

    The foreign key parameter must be a column name:

    http://www.postgresql.org/docs/current/static/sql-createtable.html

    You will have to normalize

    create table user_data (
        id int not null primary key,
        user_id int not null,
        somedata text,
        constraint fk_users_data foreign key (user_id) references Users(Id)
    );
    

提交回复
热议问题