PostgreSQL array of elements that each are a foreign key

前端 未结 2 1913
孤独总比滥情好
孤独总比滥情好 2020-11-30 01:24

I am attempting to create a DB for my app and one thing I\'d like to find the best way of doing is creating a one-to-many relationship between my Users and

2条回答
  •  隐瞒了意图╮
    2020-11-30 02:05

    It may soon be possible to do this: https://commitfest.postgresql.org/17/1252/ - Mark Rofail has been doing some excellent work on this patch!

    The patch will (once complete) allow

    CREATE TABLE PKTABLEFORARRAY (
        ptest1 float8 PRIMARY KEY,
        ptest2 text
    );
    CREATE TABLE FKTABLEFORARRAY (
        ftest1 int[],
        FOREIGN KEY (EACH ELEMENT OF ftest1) REFERENCES PKTABLEFORARRAY,
        ftest2 int
    );
    

    However, author currently needs help to rebase the patch (beyond my own ability) so anyone reading this who knows Postgres internals please help if you can.

提交回复
热议问题