我有一个python变量,它是mysql作业索引,如下所示:
index_id = 14186857如果我将使用python "cursor.execute“和特定index_id直接执行mysql语句
即,在查询中指定数字14186857,并且不使用变量index_id
语句按照预期运行,如下所示:
cursor.execute("select id_job,derived_es from job_table where db_inx=14186857")然后将输出填充到一个变量:
result = cursor.fetchall()如果我要做同样的事情,直接指定变量名index_id而不是14186857
cursor.execute("select id_job,derived_es from job_table where db_inx=index_id")
我得到以下错误:
mysql.connector.errors.ProgrammingError: 1054 (42S22): Unknown column 'index_id' in 'where clause'发布于 2019-09-10 22:44:36
您不能在引号内传递变量。试试这个:
cursor.execute("select id_job,derived_es from job_table where db_inx={}".format(index_id))https://stackoverflow.com/questions/57873125
复制相似问题