我下面有MySQL插入语句,如果有记录,我想更新所有字段(主键除外)。 因为最多有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")