I'm using github.com/bmizerany/pq against a Postgres database. I need to select all the rows in the "todos" table, and for each row check for condition and update the row accordingly. Pseudo codes:
rows, _ := dbConn.Query("SELECT id, condition, task FROM todos")
for rows.Next() {
var Id int
var Condition int
var Task string
rows.Scan(&Id, &Condition, &Task)
if Condition == 0 {
UpdateTask(Id, Task)
}
}
The UpdateTask() function will issue a SQL update statement to update the row.
Will issuing SQL update within a SELECT query lock the database? Is this the proper way of doing such update?