Created
February 8, 2014 14:29
-
-
Save qoelet/8884564 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 OR REPLACE FUNCTION fa.double_book_keeping_check() RETURNS trigger | |
AS $$ | |
BEGIN | |
IF TG_TABLE_NAME='reports' THEN | |
IF NEW.total_assets = (NEW.total_equity + NEW.total_liabilities) THEN | |
RETURN NEW; | |
ELSE | |
RAISE EXCEPTION 'BOOK KEEPING ERROR: TOTAL ASSETS DOES NOT MATCH SUM(TOTAL LIABILITIES, TOTAL EQUITY)!'; | |
END IF; | |
END IF; | |
END; | |
$$ LANGUAGE 'plpgsql'; | |
CREATE TRIGGER book_keeping_check | |
BEFORE INSERT OR UPDATE ON fa.reports | |
FOR EACH ROW | |
EXECUTE PROCEDURE fa.double_book_keeping_check(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment