[英]Differentiate a schema from a table?
In Postgresql, the query is getting an error for saying that schema "purchase_order" doesn't exist. 在Postgresql中,查询得到一个错误,指出模式“ purchase_order”不存在。
from ((select a.item_no
from stocka a
join order_item oi
on (oi.item_no = a.item_no)
join purchase_order po
on (po.order_no = oi.order_no)
where po.location = 'LocationA'
) UNION ALL
(select b.item_no
from stockb b
join order_item oi
on (oi.item_no = b.item_no)
join purchase_order po
on (po.order_no = oi.order_no)
where po.location = 'LocationB'
))
The Union
is for the from clause Union
是针对from子句的
It is for some reason saying that purchase_order isn't a table, but a schema. 由于某种原因,purchase_order不是表,而是模式。
The error you describe is not due to the code you posted, which should work - given the objects exist. 您描述的错误不是由于您发布的代码而定,只要存在对象,该代码就可以工作。
I only added an alias for the subquery : sub
(required!), simplified with USING
(optional), removed redundant parentheses and reformatted: 我只为子查询添加了一个别名 :
sub
(必需!), USING
简化(可选),删除了多余的括号并重新格式化:
SELECT *
FROM (
SELECT a.item_no
FROM stocka a
JOIN order_item oi USING (item_no)
JOIN purchase_order po USING (order_no)
WHERE po.location = 'LocationA'
UNION ALL
SELECT b.item_no
FROM stockb b
JOIN order_item oi USING (item_no)
JOIN purchase_order po USING (order_no)
WHERE po.location = 'LocationB'
) sub;
Depending on db layout (table definitions?) and exact requirements this could possibly be simplified further. 根据数据库布局(表定义?)和确切的要求,这可能会进一步简化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.