update := map[string]interface{}{ "field1": gorm.Expr("field1 + (?)", changes.Field1), "field2": gorm.Expr("field2 + (?)", changes.Field2), "field3": gorm.Expr("field3 + (?)", changes.Field3), }

The type of fields 1~3 is decimal.Decimal. When updating mysql with the update map for about hunderds of times, the decimal precision will be lost, like 3.3689999999999998.

MySQL [example]> CREATE TABLE demo ( -> id int not null primary key, -> amount decimal(27,18) not null -> ); Query OK, 0 rows affected (0.238 sec)

MySQL [example]> INSERT INTO demo values (1, 0); Query OK, 1 row affected (0.215 sec)

MySQL [example]> select * from demo; +----+----------------------+ | id | amount | +----+----------------------+ | 1 | 0.000000000000000000 | +----+----------------------+ 1 row in set (0.216 sec)

MySQL [example]> UPDATE demo SET amount = amount + '1.123'; Query OK, 1 row affected (0.219 sec) Rows matched: 1 Changed: 1 Warnings: 0

MySQL [example]> select * from demo; +----+----------------------+ | id | amount | +----+----------------------+ | 1 | 1.123000000000000000 | +----+----------------------+ 1 row in set (0.266 sec)

MySQL [example]> UPDATE demo SET amount = amount + '1.123'; Query OK, 1 row affected (0.235 sec) Rows matched: 1 Changed: 1 Warnings: 0

MySQL [example]> select * from demo; +----+----------------------+ | id | amount | +----+----------------------+ | 1 | 2.246000000000000000 | +----+----------------------+ 1 row in set (0.270 sec)

MySQL [example]> UPDATE demo SET amount = amount + '1.123'; Query OK, 1 row affected (0.417 sec) Rows matched: 1 Changed: 1 Warnings: 0

MySQL [example]> select * from demo; +----+----------------------+ | id | amount | +----+----------------------+ | 1 | 3.368999999999999800 | +----+----------------------+ 1 row in set (0.214 sec)

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: Heliner

it sounds like some future of mysql try this

CREATE TABLE demo (
 id int not null primary key,
 amount decimal(27,18) not null
);

INSERT INTO demo values (1, 0);
UPDATE demo SET amount = amount + 1.123;
select * from demo;

UPDATE demo SET amount = amount + 1.123;
select * from demo;

UPDATE demo SET amount = amount + 1.123;
select * from demo;

--id    amount
--1 1.123000000000000000
--id    amount
--1 2.246000000000000000
--id    amount
--1 3.369000000000000000

https://paiza.io/projects/lbp9qwjko_vk0oArQK00gw?language=mysql

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking