Can I do something like this in gorm , psql?
UPDATE job SET status = 'RUNNING' WHERE status =
'PENDING' RETURNING *
I want to get all rows that were changed by the update with a single atomic operation. If there are other solutions please write it.
It's possible having only a little downside as far as I know
Assuming your model is called Job
, you can do something like this...
var jobs []Job
db.Find(&jobs).Where("status = ?", StatusPending).Update("status", StatusRunning)
The lines affect will be in the jobs var
, but I have to say that you will receive the lines how they were BEFORE the Update, so the status of the models will be 'PENDING'