I am trying to create a cross join in 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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.