postgresql - 需要外键作为数组

标签 postgresql

<分区>

CREATE TABLE test ( id int PRIMARY KEY , name );

CREATE TABLE test1 ( id integer[] REFERENCES test , rollid int );

错误:外键约束“test3_id_fkey”无法实现 详细信息:键列“id”和“id”的类型不兼容:integer[] 和 integer。

之后我也尝试另一种方式

CREATE TABLE test1 ( id integer[] , rollid int);

ALTER TABLE test1 ADD CONSTRAINT foreignkeyarray FOREIGN KEY (id) REFERENCES test;

错误:无法实现外键约束“fkarray” 详细信息:键列“id”和“id”的类型不兼容:integer[] 和 integer。

所以我尝试创建一个外键数组意味着它说错误。请告诉我任何人?

postgresql 版本是 9.1。

最佳答案

您尝试做的事情根本无法完成。完全没有。没有如果,没有但是。

新建表test1_test,包含两个字段,test1_id,test_id。根据需要将外键放在那个上,并使 test1 的 id 为整数。

关于postgresql - 需要外键作为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20215724/

相关文章:

postgresql - 使用 pg_restore 进行多个转储时管理外键

postgresql - 页面管理员 4 : Cannot edit rows from one table

postgresql - 使用 Sails v1 在 Postgresql 上未定义的数据存储和模型

postgresql - 在 Okteto Cloud 上创建 PersistentVolume

php - 理解 PHP 的 include 命令

ruby-on-rails - Rails 为左连接模型命名范围

node.js - Heroku fork - 该附加计划仅适用于特定用户

sql - 如果连接表有 where 子句,则限制在主表上

security - 到 Amazon EC2 的 PostgreSQL SSH 隧道?

node.js - 成功发布到数据库后无法触发 alert()