Reputation: 321
I am attempting to run the following query in postgres:
update changeitem c inner join issuestatus s on s.id = c.oldvalue and c.field = 'status' set oldstring = s.pname;
I am getting the following error:
ERROR: syntax error at or near "inner"
LINE 1: update changeitem c inner join issuestatus s on s.id = c.old...
I am not completely sure what is wrong with my statement.
Upvotes: 0
Views: 40
Reputation: 717
What you want to do can be performed with an UPDATE WITH
clause:
update changeitem c
set oldstring = s.pname
from issuestatus s
where s.id = c.oldvalue and c.field = 'status';
see this sqlFiddle
Upvotes: 0
Reputation: 1
Correct query:
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)
Upvotes: 0
Reputation: 1120
Try This : Not Tested :
update changeitem as c set oldstring = s.pname from issuestatus as s where s.id = c.oldvalue and c.field = 'status' ;
Upvotes: 0
Reputation: 657
Unfortunately UPDATE does not support explicit joins using the JOIN keyword. Check official documentation please.
Upvotes: 1
Reputation: 7320
Try this way:
update changeitem c
set oldstring = s.pname
from issuestatus s
where s.id = c.oldvalue
and c.field = 'status';
Upvotes: 2