Вопрос

I'm trying to run the following query using 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,))

I am getting the following error:

TypeError: %d format: a number is required, not str

label, metric, table, and min_id are a string, string, string, and int, respectively.

Am I not escaping the %'s correctly? Can't quite figure this out, have tried a few things.

Thanks!

Это было полезно?

Решение

... id >= %d ... should be ... id >= %s ....

All parameters are escaped converted to strings before applied to the format string.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top