在postgres中查找连接一组节点中的节点的所有边



我将数据存储在两个名为objects和object_relationships的表中。这是一个简单的自我指代多对多。

对象表

描述1主题:关于鸟类的电子邮件电子邮件2题:鸟电子邮件34标记个人5lex个人6主题:蚂蚁电子邮件

object表中获取一个ids的数组,并按该数组的元素搜索object_relationships中的行。

select object_id, type, child_id
from (
select array_agg(id) as ids
from objects 
where description like any('{%birds%, %lex%, %john%}')
) s
join object_relationships
on object_id = any(ids) and child_id = any(ids)
order by object_id, child_id;

在db<gt;不停摆弄

最新更新