Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Update语句:错误:目标表必须是equijoin谓词的一部分_Sql_Sql Update_Amazon Redshift - Fatal编程技术网

Sql Update语句:错误:目标表必须是equijoin谓词的一部分

Sql Update语句:错误:目标表必须是equijoin谓词的一部分,sql,sql-update,amazon-redshift,Sql,Sql Update,Amazon Redshift,当我尝试更新表1中类似于表2的列的列时,会出现此错误 目标表必须是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/%'; 类别类型表如下所示: type category sandals shoes boo

当我尝试更新表1中类似于表2的列的列时,会出现此错误

目标表必须是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/%';
类别类型表如下所示:

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

我不知道红移,但在Postgres中,您不能重复UPDATE语句FROM子句中的目标表:

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/%'; 

您应该能够使用如下子查询进行连接:

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
下面的链接示例将在页面的下方显示。最后一个示例显示了子查询的好处

此查询的基本形式是:

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

我试过了。但我仍然得到一个错误:关系t1不存在。更新temp set category=t1.category(从选择c.category中)、t.link(从类别类型c中)、temp t(其中t.link类似“%”| | c.type | | |“%”和t1.link类似“%.nike.com/%”t1,其中temp.link=t1.link;我将尝试提出一个可以在集群上运行的示例。看起来我的示例在子select的where子句中有一个错误…我无法从那里引用t1。会修好的,谢谢!无法在窗口外引用t1如果只运行内部选择,它是否会像您预期的那样为您提供类别和链接列表?