Skip to content Skip to sidebar Skip to footer

Parameterize An Mysql In Clause In Python Code

I was looking at this similar question: Parameterize an SQL IN clause But the solution is not using Python, so I had to raise a new question: How do I parameterize a query containi

Solution 1:

The only answer here doesn't work, since I've resolved this, so here's the solution: turns out I only need to convert it to a list (with the square bracket), no need to remove the bracket otherwise it won't work!

Solution 2:

Maybe you can convert the column list to a tuple:

col_tuple = tuple(list)

Then use a python f-string in your query:

f"""SELECT * FROM Tags 
WHERE Name IN {col_tuple}
ORDER BY Count DESC"""

Post a Comment for "Parameterize An Mysql In Clause In Python Code"