Reputation: 23581
I'm trying to update every record in a table:
sqlDB.Table("task").Where("1=1").Update("status", 1)
And I can't avoid the 1=1
where condition. Is that the right way to do it?
Upvotes: 0
Views: 530
Reputation: 9
According to https://gorm.io/docs/update.html#Block-Global-Updates
This should work:
db.Session(&gorm.Session{AllowGlobalUpdate: true}).Model(&User{}).Update("name", "jinzhu")
Upvotes: 1
Reputation: 108841
Yes. 1=1
is a widely recognized always-true WHERE clause. Go for it.
Upvotes: 1