unnest 数组和用户提供的数据的交叉连接错误
Cross join error with unnest array and user supplied data
我正在尝试在 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);
我正在尝试在 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);