For example, here’s a table with 2 columns called USER_ID
, MY_COLUMN
. I want to change the MY_COLUMN
for a single user specified by USER_ID
.
If the modification is very naive/simple, say MY_COLUMN
is an integer and we only want to increment it by 1, we can achieve this by a simple UPDATE ... SET ... WHERE ...
statement even without using transaction.
However, if the modification is very complicated, that I can only read/get the value of MY_COLUMN
first, and then do some complicated computation using a programming language (e.g., JavaScript, Java or Golang), and finally update the value of MY_COLUMN
. If it’s this case, how can I ensure the atomicity of the above "read and write" process?
All examples I find on Internet use a long SQL statement with START TRANSACTION ... COMMIT
with possibly IF
, ROLLBACK
… And the computation is very simple that can be written in SQL language. I’m wondering how to achieve the atomicity when the computation is too complicated that can be only implemented in a high-level programming language? Could you share an example?
You need to sign in to view this answers
Leave feedback about this