backendgym backendgym · reps Sign in with GitHubSign in

07Make a transfer atomic

sql-optimizing / reps/07/README.md

In one transaction, move 30.00 from Alice's wallet to Bob's and commit. Then, in a second transaction, start a transfer of 200.00: check Alice's balance with a SELECT, see that it falls short, and end that transaction with ROLLBACK. Return both balances after each decision.

Expected: after the commit, Alice has 70.00 and Bob 80.00. After the rollback, the balances are still 70.00 and 80.00.

After the rep
  1. 1 Leave out your SELECT and run the 200.00 UPDATE anyway, then roll back. What stops it (seed/01-schema.sql has the answer if the error surprises you), and would you rather rely on that or on your check?