Answer the question
In order to leave comments, you need to log in
How to add data to table and update user if condition is met?
INSERT INTO inventory (itemid, created_at, status, userid)
SELECT UNNEST ($1::bigint[]), $2, 0, $3
WHERE EXISTS (
SELECT balance FROM users
WHERE id = $3 AND balance >= $4::numeric
)
UPDATE users
SET balance -= $4::numeric
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question