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 OR REPLACE FUNCTION check_circular_reference() RETURNS TRIGGER AS $$ | |
DECLARE | |
circular_found int; | |
BEGIN | |
IF NEW.parent_id IS NOT NULL | |
THEN | |
IF NEW.parent_id = NEW.id | |
THEN | |
RAISE EXCEPTION 'circular reference detected'; | |
END IF; |