我正在使用 pymysql 从 MySQL 数据库中获取数据但出现此错误
ProgrammingError: (1064, "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 '23:59:00' at line 1")
我的代码如下
cursor1 = price_db.cursor()
cursor1.execute('select * from bo_prices.chart_prices where price_date = {};' .format(string_time)) # Extract 'chart_price' table from price db
data7 = cursor1.fetchall()
chart_price = pd.DataFrame(data7)
string_time 是
string_time = srt(datetime.datetime.combine(datetime.date(2019,10,07), datetime.time(23,59)))
如何修复它以获取数据?谢谢!
最佳答案
您不应该对 SQL 查询使用字符串格式。
你应该使用替换。
q = "select * from bo_prices.chart_prices where price_date = '(?)'"
v = (string_time,)
cursor1.execute(q, v)
关于python - 如何修复编程错误 : (1064,“您的 SQL 语法有错误)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58391586/