mysql对所有变量进行重复密钥更新

eblbsuwk  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(203)

下面是mysql insert语句,如果有记录,我想更新所有字段(除了主键)。因为最多有80列,所以我不想逐个编写键和值对。有人能帮忙吗?
下面是我的代码:


# Save item to database

def process_item(self, item, _):
    with self.conn.cursor() as c:
        c.execute(self.query(item), item.values())
def query(self, item):
    return "INSERT INTO income_statement ({columns}) VALUES ({values}) ON DUPLICATE KEY UPDATE ({columns}) = VALUES({columns})".format(
        columns=', '.join(item.keys()),
        values=', '.join(['%s'] * len(item))
    )

我有个错误:

ProgrammingError: (1064, u"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(unit_name, fd_stock_dividend, fd_administration_fee, fd_depreciation, fd_divide' at line 1")

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题