Bird
0
0

You wrote this code in PostgreSQL:

medium📝 Debug Q14 of 15
PostgreSQL - Transactions and Concurrency
You wrote this code in PostgreSQL:
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
SELECT balance FROM accounts WHERE id = 1;
COMMIT;
But you notice the SELECT shows the updated balance even before COMMIT. Why?
ABecause the transaction reads its own uncommitted changes under Read Committed.
BBecause the isolation level is set to Read Uncommitted.
CBecause SELECT statements ignore transaction boundaries.
DBecause the UPDATE was not executed properly.
Step-by-Step Solution
Solution:
  1. Step 1: Understand transaction visibility in Read Committed

    In Read Committed, a transaction sees its own changes immediately, even if not committed yet.
  2. Step 2: Apply to given code

    The SELECT inside the same transaction sees the updated balance from the UPDATE before COMMIT.
  3. Final Answer:

    Because the transaction reads its own uncommitted changes under Read Committed. -> Option A
  4. Quick Check:

    Transaction sees own changes before commit [OK]
Quick Trick: A transaction always sees its own changes immediately [OK]
Common Mistakes:
  • Confusing Read Committed with Read Uncommitted
  • Thinking SELECT ignores transaction boundaries
  • Assuming UPDATE failed without checking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes