Is this atomic set and get in MariaDB / MySQL: `UPDATE t SET col = @my_var := col + 1 WHERE id = 123`?
0
votes
1
answer
612
views
I want to atomically update a single row and get its value.
I discovered today that MariaDB / MySQL has this additional way of setting user variables using the assignment operator
:=
, described e.g. here .
I wonder therefore if the following statement, followed by checking the value of @my_var
, accomplishes what I want:
UPDATE t SET col = @my_var := col + 1 WHERE id = 123;
It seems it should, but I'd like to confirm with the pundits.
---
(I know there's also SELECT .. FOR UPDATE
.)
Asked by Jan Żankowski
(203 rep)
May 27, 2021, 10:31 AM
Last activity: Mar 4, 2025, 01:04 AM
Last activity: Mar 4, 2025, 01:04 AM