Created
January 8, 2019 16:43
a stored function for a trigger
This file contains 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 FUNCTION account_audit_func() | |
RETURNS TRIGGER | |
AS $$ | |
BEGIN | |
IF TG_OP = 'INSERT' THEN | |
INSERT INTO account_audit (operation, account_id, account_name, debt, balance) VALUES | |
(TG_OP, NEW.*); | |
RETURN NEW; | |
ELSIF TG_OP = 'UPDATE' THEN | |
INSERT INTO account_audit (operation, account_id, account_name, debt, balance) VALUES | |
(TG_OP, NEW.*); | |
RETURN NEW; | |
ELSIF TG_OP = 'DELETE' THEN | |
INSERT INTO account_audit (operation, account_id, account_name, debt, balance) VALUES | |
(TG_OP, OLD.*); | |
RETURN OLD; | |
END IF; | |
END; | |
$$ | |
LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment