-
-
Save tcrayford/c6f732af53ac1d4df40e to your computer and use it in GitHub Desktop.
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 properties_insert_trigger() RETURNS trigger | |
LANGUAGE plpgsql | |
AS $$ | |
DECLARE | |
existing_property properties%ROWTYPE; | |
BEGIN | |
SELECT * into existing_property from properties where mls_id = NEW.mls_id and ln = NEW.ln; | |
IF FOUND THEN | |
RAISE EXCEPTION 'A property already exists with that mls_id and ln'; | |
END IF; | |
IF ( NEW.publicly_viewable is TRUE ) THEN | |
INSERT INTO properties_publicly_viewable VALUES (NEW.*); | |
ELSEIF ( NEW.publicly_viewable is FALSE ) THEN | |
INSERT INTO properties_not_publicly_viewable VALUES (NEW.*); | |
ELSE | |
RAISE EXCEPTION 'Bad publicly viewable value. Fix the properties_insert_trigger() function!'; | |
END IF; | |
RETURN NULL; | |
END; | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment