Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading