create or replace function pgbench_transaction(arg_aid int, arg_bid int, arg_tid int, arg_delta int) returns int as $$
DECLARE
  abal int;
BEGIN
UPDATE pgbench_accounts SET abalance = abalance + arg_delta WHERE aid = arg_aid;
SELECT abalance into abal FROM pgbench_accounts WHERE aid = arg_aid;
UPDATE pgbench_tellers SET tbalance = tbalance + arg_delta WHERE tid = arg_tid;
UPDATE pgbench_branches SET bbalance = bbalance + arg_delta WHERE bid = arg_bid;
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (arg_tid, arg_bid, arg_aid, arg_delta, CURRENT_TIMESTAMP);
RETURN abal;
END;
$$
language plpgsql;
