postgresql - 如何在 PostgreSQL 的一行中存储多个外键
问题描述
我有两张表,我希望能够查找所有employees
当前正在使用company
. 我的想法是在company
表中存储一组员工:
表启动。
(
employee_id serial not null
constraint employees_pk
primary key,
name text
);
create table company
(
company_id serial not null
constraint company_pk
primary key,
name text,
employees jsonb
constraint company_employee_id_fk
references employees
);
[42804] ERROR: foreign key constraint "company_employee_id_fk" cannot be implemented Detail: Key columns "employees" and "employee_id" are of incompatible types: jsonb and integer.
我想要的结果是有一个如下所示的对象:
{
"name": "A company",
"employees": [{
"name": "Jamie Hutber",
"name": "John Smith",
"name": "Frank Albert"
}]
}
解决方案
推荐阅读
- python - Python h5py - “形状元组与数据不兼容”错误
- python - 为什么每行中的方法链接与方法会导致进程被杀死或内存不足?
- powerbi - PowerBI Refresh - 仅附加在文件夹中的最新文件中
- python - 替换字符串中的特殊字符
- python - Tornado websocket 与动态 MongoDB Motor 手表
- python - 如何在python中运行多个fedora命令
- javascript - #jquery 对话框不是函数
- javascript - 如何自定义jQuery图像预览代码
- synology - 淘汰唯一的卷,保存重要的文件
- ios - 使用 StandardCyborg 3D 扫描 API 和保存数据时遇到问题