我正在尝试使用 python 执行简单的 mariadb sql 查询,但收到以下错误:
1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%s' at line 1
我是Python新手,我不知道我做错了什么。我认为该sql是有效的,因为我尝试过并且我之前也使用过相同的语法。
这是无效的代码:
import mysql.connector as mariadb
mariadb_connection = mariadb.connect()
cursor = mariadb_connection.cursor()
cursor.execute(operation="select max(parse_key) from nb.extracted_data where run_id = %s",params=(run_id))
我检查了 mysql 文档,我认为我这样做是正确的:
https://dev.mysql.com/doc/connector-python/en/connector-python-example-cursor-select.html
请帮我弄清楚我必须做什么才能纠正该陈述。
最佳答案
看起来@brentertainer 已经明白了这一点。该元组在 run_id 之后需要一个逗号,即 (run_id**,**)。
关于python - mariadb游标参数标记问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57334561/