我有这个 SQL 查询,它单独运行良好,受影响的 2 行绝对没问题
update chores set life_status ='Processing' where life_status = 'Active' and chore_type ='Shared' and money_assigned > 0
但是当我在 golang 中尝试 gorm 的执行变体语句时,即
err := h.db.Raw("update chores set life_status ='Processing' where life_status = 'Active' and chore_type ='Shared' and money_assigned > ? ", 0).Error
或
numRecsToProcess := h.db.Raw("update chores set life_status ='Processing' where life_status = 'Active' and chore_type ='Shared' and money_assigned > ? ", 0).RowsAffected
这些更新语句都不会影响基础数据库中的任何更改。 Gorm 使用功能中是否缺少某些内容?
最佳答案
尝试使用 h.db.Exec
而不是 h.db.Raw
。
关于带有 CloudSQL 的 Golang Gorm db.raw 更新 SQL 查询不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39239543/