I am using mysql.connector to query values from the database in python. I need to write a select query with "IN" in the where clause. I tried to pass the values as a list, tuple, etc. But it is throwing the error that the "Python 'data-type' cannot be converted to a MySQL type"
import mysql.connector
from mysql.connector import Error
analyticsdb = mysql.connector.connect(
pool_name = 'analyticspool',
pool_size = 10,
host="localhost",
user="root",
passwd="",
database="analytics"
)
analyticsCursor = analyticsdb.cursor(dictionary=True)
gender_values = ['Male', 'Female']
registeredQuery = "SELECT COUNT(DISTINCT uid) AS registered FROM `users` WHERE gender IN (%s)"
placeholders = (gender_values)
analyticsCursor.execute(registeredQuery, placeholders)
regCount = analyticsCursor.fetchone()