2016-12-28 17 views
1

我得到这个错误的一部分,当我尝试更新表1的列就是喜欢表的列2Update语句:错误:目标表必须是等值连接谓词

目标表必须的一部分一个equijoin谓词。如下图所示

update test 
    set category = t1.category 
from category_type t1, test t2 
where t2.link ilike '%' || t1.type || '%' 
and t2.link ilike '%.nike.com/%'; 

Category_Type表:

type  category 
sandals  shoes 
boots  shoes 
t-shirts apparel 
-pants  apparel 

回答

0

我不知道红移,但在Postgres的你一定不能重复目标表中的FROM子句UPDATE声明中:

update test t2 
    set category = t1.category 
from category_type t1 --<< do NOT repeat the target table here 
where t2.link ilike '%' || t1.type || '%' 
    and t2.link ilike '%.nike.com/%'; 
0

你应该可以加入像这样的子查询:

update test set category = t1.category 
from (
    select c.category, t.link 
    from category_type c, test t 
    where t.link ilike '%' || c.type || '%' 
     and t.link ilike '%.nike.com/%'; 
) t1 
where test.link = t1.link 

AWS docs已加入页面下方的示例。最后一个例子展示了子查询的好处。

此查询的基本形式是:

update target set val=t2.val 
from (
    select t.id, o.val 
    from target t 
    join other o on o.id=t.id 
) t2 
where target.id = t2.id 
+0

非常感谢您! – onlinetravel

+0

试过了。但我仍然得到一个错误:关系“t1”不存在。 更新临时设置类别=从t1.category ( 选择c.category,从category_type C,温度吨 其中t.link ILIKE '%' || || c.type '%' 和T1 t.link .link ilike'%.nike.com /%' )t1 其中temp.link = t1.link; – onlinetravel

+0

我会试着想出一个我可以在集群上运行的例子。 – systemjack