我试图使用PyMySQL运行以下查询

cur.execute("SELECT %s as label, UNIX_TIMESTAMP(CONVERT(DATE_FORMAT(date_added, '%%Y-%%m-%%d-%%H:%%i:00'),DATETIME)) as time, %s  as metric FROM %s WHERE id >= %d GROUP BY label, time", (label, metric, table, min_id,))

我得到以下错误:
TypeError: %d format: a number is required, not str

label、metric、table和min_id分别是string、string、string和int。
我没有正确地逃出%吗?不太明白,试过几次。
谢谢!

最佳答案

... id >= %d ...应该是... id >= %s ...
在应用到格式字符串之前,所有参数都转换为字符串。

10-05 21:02
查看更多