var username string
db.Model(&model.User{}).
Where("id = @id", sql.Named("id", 10000)).
Limit(1).
Pluck("username", username)
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: lnnt
need & before username
var username string
db.Model(&model.User{}).
Where("id = @id", sql.Named("id", 10000)).
Limit(1).
Pluck("username", &username)
Comment From: dablelv
GORM version is v1.25.1.
I encountered the same error when I use the Pluck to get single column value. My code as follow:
func GetModelStatus(id uint64) (status constants.ModelStatus, err error) {
err = Db.Model(&model.Model{}).Where("id = ?", id).Pluck("status", &status).Error
return
}
The type constants.ModelStatus defined as follow:
type ModelStatus int
Can anyone help me, thx.
Comment From: dablelv
I found taht in the low version, such as 1.24.1, the Pluck no problem.
In desperation, I use Scan indtead of Pluck to get single column value and succeeded.