-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gorm batch update question #6804
Comments
you can achieve it by using the case when syntax in mysql, but what I suggest is doing it in transaction rather than doing it in one query, I think in many senarios, the time of calling mysql doesn't matter so much. |
It is in transaction, the time of calling mysql is matter to my case. This is just a demo, i need to handle million data, so i need calling mysql once to handle for such as 500 data. |
May I know what you are updating.
|
also, keep the order of the records to prevent potential dead locks. |
I tried use "on conflict update" syntax with batch insertion, but this only support set a value to update like "amount = 1", but i can't use it to update like "amount = amount +1" this is the point. MQ performance improvement is not so much and make this update complex. I am realize a invoice system, user apply sometimes need to handle many invoice details.I will update apply amount and invoice details in transaction. |
This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days |
I can use this code to realize update for " update set amount = amount -1 where id = 1"
tx.Table(dao.TInvoiceExpense).Where("id = ?",1).Updates(map[string]interface{}{ "amount": gorm.Expr("amount - ?", 1)})
how to realize batch update for "update set amount = amount -1 where id = 1; update set amount = amount -2 where id = 2; "
call mysql once.
The text was updated successfully, but these errors were encountered: