英文:
Maximum number of values we can have in IN clause
问题
在IN
子句中我们可以拥有的值的最大数量有限制吗?
英文:
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)
答案1
得分: 1
IN子句中的值没有固定限制,无论是在5.7还是8.0版本。理论上的限制取决于您的SQL语句的长度以及max_allowed_packet
的值。
这也在MySQL文档中有记录:
"IN()列表中的值数量仅受max_allowed_packet值的限制。"
英文:
There is no fixed limit of values in the IN clause, neither in 5.7 or 8.0. The theoretical limit depends on the length of your SQL statement and the value of max_allowed_packet
.
This is also documented in the MySQL documentation:
"The number of values in the IN() list is only limited by the max_allowed_packet value."
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论