Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. CREATE OR REPLACE FUNCTION "public"."update_balance_bet"()
  2. RETURNS "pg_catalog"."trigger" AS $BODY$
  3. DECLARE
  4. currentBalance INTEGER;
  5. BEGIN
  6.  
  7. currentBalance = (SELECT balance FROM "public"."Users" WHERE id=NEW."UserId");
  8. UPDATE "public"."Users" SET balance=(NEW.amount+currentBalance);
  9. RETURN NEW;
  10. END
  11. $BODY$
  12.  
  13. CREATE TRIGGER bet_trigger
  14. AFTER INSERT ON "public"."Bets"
  15. FOR EACH ROW
  16. EXECUTE FUNCTION update_balance_bet();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement