在使用IN查询的时候,对应的切片的数量占用了累加到使用占位符的数量
CREATE TABLE `codes` (
`id` int unsigned NOT NULL AUTO_INCREMENT ,
`code` varchar(50),
PRIMARY KEY (`id`) USING BTREE
);
package main
import (
"strings"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
func main() {
dsn := "root:123456@tcp(127.0.0.1:3306)/test1?charset=utf8mb4&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
panic("failed to connect database")
}
codeList := strings.Split(strings.Repeat("s", 1000000), "")
sql := `SELECT
id,
code
FROM codes
WHERE code IN ?
and id = ?
`
s := codeList[:65535]
var res []map[string]interface{}
err = db.Raw(sql, s, 1).Scan(&res).Error
if err != nil {
panic(err) // panic: Error 1390 (HY000): Prepared statement contains too many placeholders
}
}
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: a631807682
refer to https://github.com/go-gorm/gorm/issues/6849#issuecomment-1960831781