Advertisement
CyberN00b

Untitled

Oct 14th, 2023
981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH user_info AS (
  2.     SELECT user_id FROM hello_schema.users
  3.     WHERE user_id = uuid($1)
  4.  ),
  5.     balance_info AS (
  6.     UPDATE hello_schema.user_balance
  7.         SET balance = balance + $2
  8.     WHERE user_id = (SELECT user_id FROM user_info) AND ($2 >= 0 OR balance > abs($2))
  9.     RETURNING balance
  10.  )
  11. SELECT (SELECT user_id FROM user_info), (SELECT balance FROM balance_info);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement