How in Postgresql inside a transaction to get values into a variable, and if SELECT did not return anything, throw an error, and if SELECT returned data, then use them in the transaction?
Like this:
BEGIN;
@activeRounds = SELECT * FROM "rounds" WHERE status = 'active';
if(!@activeRounds) {
RAISE ERROR "Has no Active rounds"
};
INSERT INTO "bet"
(user_id, round_id)
VALUES
(100, @activeRound[0].id)
COMMIT;
how to do something similar in one request within a transaction?