Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Last active October 10, 2021 10:27
Show Gist options
  • Save MartinThoma/bffe38ba5284f3f11189c8f605247e6b to your computer and use it in GitHub Desktop.
Save MartinThoma/bffe38ba5284f3f11189c8f605247e6b to your computer and use it in GitHub Desktop.
-- Transaction 2 Transaction 1
# UPDATE balances SET balance = 500;
UPDATE 2
# start transaction isolation level read committed;
START TRANSACTION
# SELECT SUM(balance)
FROM balances
WHERE id in ('Alice', 'Bob');
sum
------
1000
(1 row)
SELECT transfer_out('Alice', 400);
SELECT transfer_out('Bob', 400);
SELECT * FROM balances;
id | balance
-------+---------
Alice | 100
Bob | 100
# SELECT *
FROM balances
WHERE id in ('Alice', 'Bob');
id | balance
-------+---------
Alice | 100
Bob | 100
(2 rows)
# END;
COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment