You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var id uint = 1
DB.Table("users").Where("id = ?", id).Find(&users)
DB.Table("users").Where("id = ?", &id).Find(&users)
When using a value or a pointer, this kind of code behaves the same way
ids := []uint{1, 2, 3}
DB.Table("users").Where("id IN (?)", ids).Find(&users)
DB.Table("users").Where("id IN (?)", &ids).Find(&users)
I would assume that this would also happen with slices.
With a simple slice, SELECT * WHERE id IN (?) gets expanded to SELECT * WHERE id IN (?,?,?).
But with a slice pointer, this does not happen.
This case was specially annoying to pinpoint because the query returns this error Failed, got error: sql: converting argument $1 type: unsupported type []uint, a slice of uint. Later I found that this error was in the go sql package. Now makes sense, but at first glance I did not know if the error was in the gorm code or not.
Do you intend to support this case? If so, I think, I can implement it. Just need to know how is the more "gorm" like approach. I would suspect it would be reflection. I think I have seen code that does the slice pointer slice somewhere already.
The text was updated successfully, but these errors were encountered:
GORM Playground Link
go-gorm/playground#682
Description
When using a value or a pointer, this kind of code behaves the same way
I would assume that this would also happen with slices.
With a simple slice,
SELECT * WHERE id IN (?)
gets expanded toSELECT * WHERE id IN (?,?,?)
.But with a slice pointer, this does not happen.
This case with a pointer slice is not handled in https://github.com/go-gorm/gorm/blob/master/clause/expression.go#L41
I think the same happens with
clause.Where
This case was specially annoying to pinpoint because the query returns this error
Failed, got error: sql: converting argument $1 type: unsupported type []uint, a slice of uint
. Later I found that this error was in the go sql package. Now makes sense, but at first glance I did not know if the error was in the gorm code or not.Do you intend to support this case? If so, I think, I can implement it. Just need to know how is the more "gorm" like approach. I would suspect it would be reflection. I think I have seen code that does the slice pointer slice somewhere already.
The text was updated successfully, but these errors were encountered: