I want to do a select and update in a single query in PostgreSQL 9.4. I used below command for that
UPDATE (SELECT t2.pid, t1.pid as newid
FROM table1 AS t1
INNER JOIN table2 AS t2
ON t1.uid = t2.uid
) AS t
SET t.newid = t.pid';
When executing the above, I'm getting below error.
ERROR: syntax error at or near "("
LINE 2: (SELECT t2.pid, t1.pid as n...
^
SQL state: 42601
Character: 25
I executed
SELECT t2.pid, t1.pid as newid
FROM table1 AS t1
INNER JOIN table2 AS t2
ON t1.uid = t2.uid
part separately and I worked fine. Do I miss something in the update query?