Created
August 17, 2018 13:47
-
-
Save ecthiender/f25e3bd1fe254a0ed20b63b0bc8d1224 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Create the function | |
CREATE FUNCTION insert_deposit() | |
RETURNS trigger AS $BODY$ | |
DECLARE active_account BOOLEAN; | |
BEGIN | |
IF NEW."deposit_amount" <= 0 THEN | |
RAISE EXCEPTION 'Deposit amount must be greater than 0'; | |
END IF; | |
SELECT a.is_active INTO active_account FROM "account_savings" a WHERE a.account_no = NEW."account_no"; | |
IF active_account != TRUE THEN | |
RAISE EXCEPTION 'Account must be active'; | |
END IF; | |
RETURN NEW; | |
END; | |
$BODY$ LANGUAGE plpgsql; | |
--- Create the trigger with the above function | |
CREATE TRIGGER insert_deposit BEFORE INSERT OR UPDATE ON "deposit_activity" FOR EACH ROW EXECUTE PROCEDURE insert_deposit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment