我正试图在postgres中创建一个交叉连接。
SELECT * FROM (SELECT unnest(ARRAY[1,2])) AS t1(product_id)
CROSS JOIN
SELECT * FROM (SELECT unnest(ARRAY[5])) AS t2(category_id);
这给出了错误。我无法理解这个问题。
你的查询有不必要的嵌套层次,这最终会导致问题,因为一些衍生表(即子查询)不是别名。
你可以直接将其表述为
select t1.product_id, t2.category_id
from unnest(array[1,2]) as t1(product_id)
cross join unnest(array[5]) AS t2(category_id);
这样也可以
select * from
unnest(array[1,2]) t1(product_id),
unnest(array[5]) t2(category_id);