简体   繁体   English

未嵌套数组和用户提供的数据的交叉连接错误

[英]Cross join error with unnest array and user supplied data

I am trying to create a cross join in postgres我正在尝试在 postgres 中创建交叉连接

SELECT * FROM (SELECT unnest(ARRAY[1,2])) AS t1(product_id)
CROSS JOIN
SELECT * FROM (SELECT unnest(ARRAY[5])) AS t2(category_id);

This gives error.这给出了错误。 I can not figure the problem.我想不出这个问题。

Your query has unnecessary levels of nesting, which finally cause problem since some of the derived tables (ie subqueries) are not aliases.您的查询具有不必要的嵌套级别,这最终会导致问题,因为某些派生表(即子查询)不是别名。

You could just phrase this as:您可以将其表述为:

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);

This works as well这也有效

select * from 
    unnest(array[1,2]) t1(product_id), 
    unnest(array[5]) t2(category_id);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM