Hi guys, today I am testing gorm (gorm.io/gorm v1.23.8 // indirect) upsert and getting this error below. Is this fixed already? How can avoid it?
ERROR: ON CONFLICT DO UPDATE command cannot affect row a second time (SQLSTATE 21000)
My code
err := database.db.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "sku"}, {Name: "country"}},
DoUpdates: clause.AssignmentColumns([]string{"quantity"}),
}).CreateInBatches(&products, 5000).Error
type Product struct {
gorm.Model
Sku stringgorm:"index:,unique,composite:myname"Country stringgorm:"index:,unique,composite:myname"Name string
Quantity int
}
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: jolienai
Never mind, just removed duplicated values from array
Comment From: allidoisace
@jolienai How did you end up removing the duplicate values?
Comment From: jolienai
I just write the deduplicated method here https://github.com/jolienai/go-products-api/blob/main/cmd/app/jobs/product_bulk_job.go#L60