Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make ARRAY field with foreign key constraint in SQLAlchemy?

How to make column with ARRAY(Integer) type, where each integer is primary key from some other table? If it's impossible, how to achieve similar table relationships with other method?

like image 808
DSblizzard Avatar asked Feb 21 '14 10:02

DSblizzard


People also ask

Can a foreign key be an array?

Not possible, but might be in the future. Foreign Key Arrays is a work in progress in PostgreSQL. Alternatively, you can do the usual approach of creating a junction(or join) table for this.

What is foreign key in SQLAlchemy?

A foreign key in SQL is a table-level construct that constrains one or more columns in that table to only allow values that are present in a different set of columns, typically but not always located on a different table.


1 Answers

As of PostgreSQL 9.3, this is not implemented, see http://blog.2ndquadrant.com/postgresql-9-3-development-array-element-foreign-keys/ One should turn array into other table.

like image 68
DSblizzard Avatar answered Sep 16 '22 18:09

DSblizzard