.Raw("select sum(points) as cnt from xx where task_id in ? ", taskIDList).Find(&sum).Error
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: ivila
@Zzy413341422 First, its recommended to give a reproduction steps instead of just a one line broken code, it's hard for others to investigate and just wasting time.
you miss some important information in your issue due to "missing reproduction steps", for example: 1, what version of gorm you are using 2, what version of golang you are using 3, what is the "concurrency scenario" for example, I have a concurrent demo codes:
// go version: go1.21.0 linux/amd64
// gorm.io/gorm v1.25.5
// gorm.io/driver/mysql v1.5.2
func runConcurrency(db *gorm.DB, concurrency int, repeatTimes int) {
wg := sync.WaitGroup{}
var idList = []uint64{1, 2, 3}
for i := 0; i < concurrency; i++ {
wg.Add(1)
go func(id int) {
defer wg.Done()
var sum int64
for j := 0; j < repeatTimes; j++ {
err := db.Raw("select count(1) + 1 as cnt from product where id in ?", idList).Find(&sum).Error
if err != nil {
panic(fmt.Sprintf("err happend at id %d, err is %v", id, err))
}
}
}(i)
}
wg.Wait()
}
this code will run very well without any error.
I suspect you are using an older version of gorm(or even the jinzhu.com/gorm), and with that version, you will need to use other functions to achieve you goal, just rewrite your codes to the following:
// 1, add brackets around the question mark when using in query, to fix the error of "expected 2 arguments, got 4"
// 2, use the Count method instead of Find method, to fix the error of "invalid value, should be pointer to struct or slice"
.Raw("select sum(points) as cnt from xx where task_id in (?) ", taskIDList).Count(&sum).Error
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: ivila
@Zzy413341422 if the issue had been fixed, please close it, thanks for the effort.
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 ✨