为什么这个带有with语句的postgresql批量更新语句不起作用?

zkure5ic  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(325)

为什么postgresql语句不起作用?

with updatedcontacts (contact_id, list_id, firstname) as 
 values (13680724,457,'James'),(13680723,457,'Stanley') 
update contacts c 
  set c.firstname = u.firstname 
from updatedcontacts u 
where u.contact_id = c.contact_id 
  and u.list_id = c.list_id;

抛出错误:
错误:“values”行52处或附近出现语法错误:…updatedcontacts(contact\u id,list\u id,firstname)作为值(^sql state:42601 character:2944)

b0zn9rqh

b0zn9rqh1#

values 应该用附加括号括起来:

with updatedcontacts (contact_id, list_id, firstname) as 
    (values (13680724,457,'James'),(13680723,457,'Stanley'))
...

相关问题