1

If I do a query like

insert into sometable b + 10 from select b from (select b from sometable order by id desc limit 1)

Is this operation atomic? That is, would it be possible for an insert into sometable to change the value of b AFTER is has been queried, but before the insert completes, causing the insert to get the wrong value?

Benubird
  • 18,551
  • 27
  • 90
  • 141

1 Answers1

-1

My guess is that it is not. You can lock it to make sure it doesn't change:

INSERT INTO sometable (b)
SELECT b+10
FROM sometable
ORDER BY id DESC
LIMIT 1
LOCK IN SHARE MODE
Vatev
  • 7,493
  • 1
  • 32
  • 39