RedShift 中更新语句中的表别名

Posted

技术标签:

【中文标题】RedShift 中更新语句中的表别名【英文标题】:Table aliasing in update statement in RedShift 【发布时间】:2018-10-24 15:49:59 【问题描述】:

我有一个如下的 sql 语句,我正在尝试将其转换为 Redshift。

update #tmpHist l 
set spread = lh.spread
from table1 lh 
where  
    l.id=lh.id 

但它给出的错误是:

[Amazon](500310) Invalid operation: syntax error at or near "l" 

有没有办法在不指定整个表的情况下给表起别名。

【问题讨论】:

文档明确指出不允许使用别名:docs.aws.amazon.com/redshift/latest/dg/…。 【参考方案1】:

正确的语法是:

UPDATE table_name SET column = 表达式 |默认 [,...]

[来自列表]

[WHERE 条件]

使用FROM 子句加入其他表。

你可以试试这个。

update #tmpHist  
set spread = lh.spread
from table1 lh 
where  
    #tmpHist.id=lh.id 

或者您可以尝试使用update .... join 作为别名。

update l 
set spread = lh.spread
from table1 lh join #tmpHist on l.id=lh.id 

【讨论】:

以上是关于RedShift 中更新语句中的表别名的主要内容,如果未能解决你的问题,请参考以下文章