簡體   English   中英

OperationalError:接近“系統”:語法錯誤

[英]OperationalError: near "System": syntax error

OperationalError                          Traceback (most recent call last)
<ipython-input-7-e63de1bbf3b5> in <module>()

      1 for row in df.iterrows():
      2        sql = 'INSERT INTO salesdata ({}) VALUES ({})'.format(','.join(df.columns), ','.join(['?']*len(df.columns)))
----> 3        c.execute(sql, tuple(row[1]))
      4 conn.commit()

我得到 OperationalError: near "System": syntax error 。 我嘗試在單引號之間插入更多空格並刪除空格,但它不起作用。 我如何使此代碼工作?

大概你的列名之一是System 這是 MySQL 8.0 中的保留字,因此需要對其進行轉義。 您應該用反引號將所有列名括起來。

sql = 'INSERT INTO salesdata ({}) VALUES ({})'.format(','.join('`' + col + '`' for col in df.columns), ','.join(['?']*len(df.columns)))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM