如何在 PostgreSQL 中编写 select 查询以遍历由 select 查询返回的数组

how to write select query in PostgreSQL to iterate over an array which is returned by a select query

SELECT b_items_p_id FROM  public.box WHERE b_id =1

and this is what it returns:

{1,3,5}

现在,对于这些值中的每一个,即 1、3 和 5,我想 运行 另一个 select 查询:

select p_desc from public.products where p_id = 1

您可以使用 any() 运算符连接 boxproducts,如下所示:

select p_desc 
from public.box b 
inner join public.products p on p.p_id = any(b.b_items_p_id)
where b.b_id =1