Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Created October 10, 2021 10:30
Show Gist options
  • Save MartinThoma/10bde6346b5212cb54e5ecd9ab19fabd to your computer and use it in GitHub Desktop.
Save MartinThoma/10bde6346b5212cb54e5ecd9ab19fabd to your computer and use it in GitHub Desktop.
# UPDATE balances SET balance = 500;
UPDATE 2
# start transaction isolation level repeatable read;
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 | 500
Bob | 500
(2 rows)
# END;
COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment