python - mariadb游标参数标记问题

标签 python mysql python-3.x mariadb

我正在尝试使用 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/

相关文章:

python - 在 Python 字符串中同时包含单引号和双引号

python - TensorFlow 中的 GRUCell : TypeError got multiple values for keyword argument 'num_units'

php - 查询计数和功能无法正常工作

php - 在 php 中显示图像

python-3.x - 如何在 Pandas 中找到完整的空行

python - Argparse 与函数的交互

python - 没有错误记录失败的 Postgres/Psycopg2 copy_from

python - 为什么 Tkinter.TopLevel.wm_geometry() 返回 "1x1+0+0"?

c# - 查询在 phpMyAdmin 中工作正常,但在应用程序中则不行(C#)

Python 游戏服务器