Hi!
To Simulate a situation where the same transfer operation is executed more than once, as might happen in a real system due to network retries or duplicate requests.
CREATE TABLE accounts (id SERIAL PRIMARY KEY,name TEXT NOT NULL,balance INT NOT NULL CHECK (balance >= 0),last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
inserting values to the table accounts,
INSERT INTO accounts (name, balance) VALUES ('Alice', 1000),('Bob', 500);
to observe whether the accpunt balance is affected the deduction and credit operations performed multiple times
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE name = 'Alice';
UPDATE accounts SET balance = balance + 100 WHERE name = 'Bob';
COMMIT;
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE name = 'Alice';
UPDATE accounts SET balance = balance + 100 WHERE name = 'Bob';
COMMIT;
to analyze whether the system prevents duplicate processing or allows the same transaction to be applied repeatedly
*it does not automatically prevent duplicate processing of the same transaction.
Top comments (0)