San9096
San9096

Reputation: 251

Django - TypeError: not enough arguments for format string

I'm trying to make a raw query on Django, here is what i tried:

Summary = myTable.objects.raw("SELECT FROM_UNIXTIME (unixtime, '%Y/%m/%d') AS ndate, count(id) AS query_count FROM myTable GROUP BY ndate ORDER BY query_count DESC")

The problem is that i keep getting the following error: TypeError: not enough arguments for format string

What is the problem here? If i execute this query on MYSQL, it will work. Any advice is appreciated!

Upvotes: 1

Views: 1209

Answers (1)

Andrey
Andrey

Reputation: 156

From my point of view, '%Y/%m/%d' waiting until values are provided like you do in string.format() function. From docs:

Note that if you want to include literal percent signs in the query, you have to double them in the case you are passing parameters:

cursor.execute("SELECT foo FROM bar WHERE baz = '30%'") # error cursor.execute("SELECT foo FROM bar WHERE baz = '30%%'")

Upvotes: 2

Related Questions