且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PostgreSQL 元素数组,每个元素都是外键

更新时间:2023-02-05 14:32:52

不,这是不可能的.

PostgreSQL 是一个关系 DBMS,在正确规范化的数据模型上运行最有效.数组 - 根据定义,它们是有序集 - 不是关系数据结构,因此 SQL 标准不支持在数组元素上定义外键,PostgreSQL 也不支持.

PostgreSQL is a relational DBMS, operating most efficiently on properly normalized data models. Arrays are - by definition, they are ordered sets - not relational data structures and the SQL standard therefore does not support defining foreign keys on array elements, and neither does PostgreSQL.

但是,您可以使用链接到其他表中的主键的数组元素构建完美的数据库.然而,这些数组元素不能被声明为外键,因此 DBMS 将不会保持引用完整性.

You can, however, build a perfectly fine database with array elements linking to primary keys in other tables. Those array elements, however, can not be declared to be foreign keys and the DBMS will therefore not maintain referential integrity.