2016-12-28 20 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