1

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!

1 Answer 1

2

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%%'")

Sign up to request clarification or add additional context in comments.

1 Comment

I tried to put a date instead of that, but it still doesn't work; also the same exact query works on mysql but not with django

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.