IN子句中可以包含的最大值数量

huangapple go评论74阅读模式
英文:

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."

huangapple
  • 本文由 发表于 2023年2月18日 12:09:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75491129.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定