【问题标题】:How to update a column in all rows of a table?如何更新表的所有行中的列?
【发布时间】:2018-10-27 19:53:43
【问题描述】:

我有代码:

def show_dolar_today(self):

    rate = self.get_dolar_today()
    self.env.cr.execute('update product_rate set rate=%s where id=%s', (rate,1))

id = 1 的记录在表中已更新,但我想更新表中的所有记录,我该怎么做?

【问题讨论】:

    标签: python sql postgresql sql-update


    【解决方案1】:

    只需删除where 子句:

    self.env.cr.execute('update product_rate set rate=%s', (rate,))
    

    【讨论】:

    • 你错过了逗号(rate,)吗?
    • @Sami 逗号是有意的 - 没有它,它只是 rate 在括号中。有了它,它是一个元组,具有单个元素 rate
    猜你喜欢
    • 2013-04-10
    • 2012-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-17
    • 2023-02-01
    相关资源
    最近更新 更多