-2

I have a query that have to get as params month.

Query below work fine and filter based on first month.

        """SELECT i.date, i.title, i.img, i.video FROM table as i """
                """WHERE MONTH(STR_TO_DATE(i.date, "%M %D %Y") ) = 1  """ \
                """ORDER BY (i.id) desc""")

When tryig to put month as parameter im receiving a error

TypeError: 'int' object is not iterable

     """SELECT i.date, i.title, i.img, i.video FROM table as i """
                """WHERE MONTH(STR_TO_DATE(i.date, "%M %D %Y") ) = %s  """ \      
                """ORDER BY (i.id) desc""", (1))

Have tried with some brackets (1), (1,), [1] but wont work.

In sql the query work fine.

Random Davis
  • 5,623
  • 3
  • 13
  • 24

1 Answers1

0

Changing % with %% at date and using tuple solve the issue (1,)

cursor.execute(
            """SELECT i.date, i.title, i.img, i.video FROM table as i """
            """WHERE MONTH(STR_TO_DATE(i.date, "%%M %%D %%Y") ) = %s  """ \    
            """ORDER BY (i.id) desc""", (1,))