运行查询时内部联接问题

时间:2015-12-15 17:28:38

标签: database postgresql

我试图在postgres中运行以下查询:

update changeitem c inner join issuestatus s on s.id = c.oldvalue and c.field = 'status' set oldstring = s.pname;

我收到以下错误:

ERROR:  syntax error at or near "inner"
LINE 1: update changeitem c inner join issuestatus s on s.id = c.old...

我不完全确定我的陈述有什么问题。

5 个答案:

答案 0 :(得分:2)

尝试这种方式:

update changeitem c 
set oldstring = s.pname
from issuestatus s 
where s.id = c.oldvalue 
and c.field = 'status';

答案 1 :(得分:1)

不幸的是,UPDATE不支持使用JOIN关键字进行显式连接。请检查official documentation

答案 2 :(得分:0)

正确查询:

UPDATE c 
SET oldstring = s.pname
FROM changeitem c 
WHERE c.field = 'status' 
AND c.id in (SELECT s.id FROM issuestatus s WHERE s.id = c.oldvalue)

答案 3 :(得分:0)

试试这个: 未经测试:

update changeitem as c set oldstring = s.pname from issuestatus as s where s.id = c.oldvalue and c.field = 'status' ;

答案 4 :(得分:0)

您可以使用UPDATE WITH子句执行您要执行的操作:

update changeitem c 
set oldstring = s.pname
from issuestatus s
where  s.id = c.oldvalue and c.field = 'status';

请参阅this sqlFiddle