| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The bumpCounter example reads a row and writes counter+1 in a transaction without locking. Under READ COMMITTED (the default) two concurrent runs can both read the same value and lose an update. Add a short section pointing at SELECT ... FOR UPDATE and SERIALIZABLE + retry. Addresses sqlc-dev#3485
| Back | FazBrowse Home | New Git URL |
What
The Using transactions how-to's bumpCounter example reads a row and then writes counter + 1 inside a transaction:
Under the default isolation level (READ COMMITTED, on both PostgreSQL and MySQL/InnoDB), two transactions running this concurrently can both read the same counter and both write the same counter + 1 — a lost update. The page presents this as the standard pattern with no caveat, which is what #3485 flags.
Change
Docs only. Adds a short Concurrent read-modify-write section after the examples:
Existing examples are unchanged — they still demonstrate WithTx, which is the page's purpose.
Closes #3485