Golang Gorm db.raw与用于更新SQL查询的CloudSQL不工作?
我有一个SQL查询,它在隔离状态下可以很好地处理2行数据Golang Gorm db.raw与用于更新SQL查询的CloudSQL不工作?,go,google-cloud-sql,go-gorm,Go,Google Cloud Sql,Go Gorm,我有一个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 li
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
或
这些update语句都不会影响基础数据库中的任何更改。Gorm使用功能中是否缺少某些功能?请尝试
h.db.Exec
而不是h.db.Raw
谢谢!它起作用了。。。也许原始SQL执行在go gormI中有这样的限制。我简单地看了一下代码,Raw()不会立即执行任何东西。您必须对返回的句柄调用其他方法。因为这回答了您的问题,您介意将其标记为接受的答案@amandepmidha吗?我还发现它可以解决类似的问题。
numRecsToProcess := h.db.Raw("update chores set life_status ='Processing' where life_status = 'Active' and chore_type ='Shared' and money_assigned > ? ", 0).RowsAffected