我试图在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...
我不完全确定我的陈述有什么问题。
答案 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';