本文主要是介绍pymssql查询传参为数量较大的tuple时报错原因分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.报错代码:pymssql._pymssql.OperationalError: (8632, b'Internal error: An expression services limit has been reached. Please look for potentially complex expressions in your query, and try to simplify them.DB-Lib error message 20018, severity 17:\nGeneral SQL Server error: Check messages from the SQL Server\n')
2.检索对应报错代码官方文档说明MSSQLSERVER_8632 - SQL Server | Microsoft LearnMSSQLSERVER_8632https://learn.microsoft.com/zh-CN/sql/relational-databases/errors-events/mssqlserver-8632-database-engine-error?view=sql-server-ver16
3.分析原因得出大概率是传参元组的数量过大导致报错
4.尝试只用该元组的前10值作为新元组传参测试,可以正常查询
5.尝试探索元组峰值,大概位于30000-40000之间
6.解决方法:(1)根据峰值分割元组,在限制范围内多次查询子元组后汇总数据;
(2)修改查询语句,'select * from XX where y in %s',tuple改为:
‘select * from XX where y in %s or y in %s ...or y in %s.’,tuple1,tuple2,...tupleN
(3)其他
这篇关于pymssql查询传参为数量较大的tuple时报错原因分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!