【问题标题】:Why does this postgresql bulk update statement with a with statement not work?为什么这个带有 with 语句的 postgresql 批量更新语句不起作用?
【发布时间】:2020-07-24 03:41:00
【问题描述】:

为什么这个 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;

抛出错误:

错误:“值”处或附近的语法错误第 52 行:...updatedcontacts (contact_id, list_id, firstname) 作为值 ( ^ SQL 状态:42601 字符:2944

【问题讨论】:

    标签: sql postgresql sql-update common-table-expression


    【解决方案1】:

    values 应该用额外的括号括起来:

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

    【讨论】:

    • @Adronicus 。 . .有趣的。我将其表述为 CTE 需要额外的括号,但效果是一样的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 1970-01-01
    相关资源
    最近更新 更多