我有两张桌子
junk=# select * from t;
name | intval
----------+--------
bar2 | 2
bar3 | 3
bar4 | 4
(3 rows)
和
junk=# select * from temp;
id | name | intval
----+------------+--------
1 | foo | 0
2 | foo2 | 2
3 | foo3 | 3
4 | foo4 | 4
5 | foo5 | 5
(5 rows)
现在,我想使用 from 中的值table t
来更新table temp
. 基本上,我想用 bar2、bar3 和 bar4 替换 temp 中第二、第三和第四个值中的名称列。
我使用 COPY 语句创建了表 t。我正在做批量更新,我正在尝试优化它。
所以,我得到这个错误。我认为这是非常基本的一个。
junk=# UPDATE temp FROM t SET name=t.name FROM t WHERE intval=t.intval;
ERROR: syntax error at or near "FROM"
LINE 1: UPDATE temp FROM t SET name=t.name FROM t WHERE intval=t.int...
^
junk=#
现在,这行得通。
UPDATE test SET name=t.name FROM t WHERE test.intval=t.intval