【问题标题】:UPDATE statement error - MySQLdb/PythonUPDATE 语句错误 - MySQLdb/Python
【发布时间】:2013-06-17 01:46:46
【问题描述】:

我正在测试表中现有记录的 UPDATE 语句。它看起来像这样:

term = 'example-column'
termInserted = term + '_inserted'
mostRecentRecord = 6
nResult = 777
bResultsInserted = 77

#print(termInserted)
cur.execute("UPDATE `term_results` SET `%s` = %s, `%s` = %s WHERE `results_id` = %s", (term, nResult, termInserted, bResultsInserted, mostRecentRecord))
connectToDb.commit()

当我运行此代码时,我收到以下错误:

Error 1054: Unknown column ''example-column'' in 'field list'

我无法理解,因为该列确实以该名称存在。你能帮我吗?谢谢。

【问题讨论】:

  • 另外 - 当我在 PHPMyAdmin 中运行等效的 SQL 语句时,它按预期工作。
  • 请添加“EXPLAIN term_results”的模式输出

标签: python mysql mysql-python


【解决方案1】:

我解决了。代码应如下所示:

cur.execute("""UPDATE `term_results` SET `%s` = %s, `%s` = %s WHERE `results_id` = %s""" % (term, nResult, termInserted, bResultsInserted, mostRecentRecord))

【讨论】:

    猜你喜欢
    • 2014-10-27
    • 2021-01-16
    • 1970-01-01
    • 2016-02-24
    • 2020-10-26
    • 1970-01-01
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多