将 array(bigint) 拆分为多行 bigint

Split array(bigint) to multiple rows of bigint

我正在查询一些 data (SQL, presto),每个项目都可以是另一个项目的父项或子项。 parent IDschild IDs 作为数组 (bigint) 存储在该主 ID 的行中。每个任务可以是多个父项的子项。

它看起来像:

id | parent_ids | child_ids
1 | [3] | []
2 | [3] | []
3 | [] | [2,1]
4 | [] | [5]
5 | [4, 6] | []
6 | [] | [5]

我想要一个包含所有 parent Ids 和每个 children 的列表作为该父项的附加行:

id | child
3 | 1
3 | 2
4 | 5
6 | 5

知道如何实现吗?

我想你想要:

select p.parent_id as id, t.id as child_id
from t cross join 
     unnest(t.parent_ids) p(parent_id)