I have a simple UPDATE SQL statement that I am trying to execute:
if err := gormDB.Raw("UPDATE orders SET item_id = ? WHERE client_id = ?", "item1", "client1").Error; err != nil {
return err
}
No errors are being returned, but my query is seemingly not being executed on the database. Nothing is logged, and no database changes are persisted.
2
Answers
Calling
Raw
by itself does not execute the query. One way to execute the operation and to retrieve the results is using theRows()
method:In my case however, I did not need to access the returned result, so I opted to use the
Exec
method, which immediately executes the given SQL:generally, it use to query.