Postgres creating a Table with an array of foreign keys

冷暖自知 提交于 2019-12-23 12:35:34

问题


I am making a table named "routes". I want it to be able to contain a list of flights in it. The flights' details are in the flights tables. I want "flight" to be an array of foreign key ids from the flights table. So, I have this code:

CREATE TABLE routes (
id SERIAL PRIMARY KEY,
flight integer[] ELEMENT REFERENCES flights,
user CHARACTER VARYING(50)
);

But, it gives the error:

ERROR:  syntax error at or near "ELEMENT"
LINE 2:     id SERIAL PRIMARY KEY, flight integer[] ELEMENT REFERENC...

I am using psql (9.3.10)

I have used this: http://blog.2ndquadrant.com/postgresql-9-3-development-array-element-foreign-keys/ as a reference, but when I copy that syntax it gives this error.

This is the syntax that I am using as a reference:

CREATE TABLE races (
   race_id integer PRIMARY KEY,
   title text,
   race_day DATE,
   ...
   practice1_positions integer[] ELEMENT REFERENCES drivers,
   practice2_positions integer[] ELEMENT REFERENCES drivers,
   practice3_positions integer[] ELEMENT REFERENCES drivers,
   qualifying_positions integer[] ELEMENT REFERENCES drivers,
   final_positions integer[] ELEMENT REFERENCES drivers
);

回答1:


The blog you link to states clearly it's just a patch that was proposed for 9.3. It didn't make it into 9.3 nor 9.4 You can comb the mailing list and try to patch your installation yourself or you can just change your schema.

If you want the details on what happened to that feature you probably should mail the author.



来源:https://stackoverflow.com/questions/34156695/postgres-creating-a-table-with-an-array-of-foreign-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!