Minus One Or Zero
stock holds one row: sku = 'A-40', qty = 1. Both sessions run at PostgreSQL's default READ COMMITTED.
| time | Session 1 | Session 2 |
|---|---|---|
| t1 | BEGIN; |
|
| t2 | BEGIN; |
|
| t3 | UPDATE stock SET qty = qty - 1 WHERE sku = 'A-40' AND qty > 0; reports UPDATE 1 |
|
| t4 | UPDATE stock SET qty = qty - 1 WHERE sku = 'A-40' AND qty > 0; blocks |
|
| t5 | COMMIT; |
|
| t6 | statement returns |
What does session 2 report at t6, and what is qty after both sessions commit?
Sign in to answer questions and track your progress
Sign In