0
votes

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.

1
Not sure if that's even possible and I wouldn't complicate things that much. You have RowsAffected but that only returns the count of rows that have been updated. Also you can use Transactions - Mario Pérez

1 Answers

0
votes

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'