Maximum value we can have in in clause

Is there a limit to the maximum number of values we can have in the in clause

sql_query = """SELECT * FROM table1
               WHERE column1 IN %(list_of_values)s
               ORDER BY CASE
               WHEN column2 LIKE 'a%' THEN 1
               WHEN column2 LIKE 'b%' THEN 2
               WHEN column2 LIKE 'c%' THEN 3
               ELSE 99 END;"""

params = {'list_of_values': list_of_values}

cursor.execute(sql_query, params)

>Solution :

Yes there is a limit. The maximum allowed number of values in the IN clause in MySQL 5.7 (and earlier) is 1000. If you include more than 1000 values, you will get an error.

Leave a Reply