Simplify your code in various ways:
CREATE FUNCTION apply_func()
RETURNS trigger AS
$func$
BEGIN
IF NOT noGrade_check(NEW.studid) THEN
RAISE NOTICE 'DECLINED: NULL GRADE EXISTS';
ELSIF NOT yrlvl_check(NEW.studid) THEN
RAISE NOTICE 'DECLINED:YRLVL_CHECK';
ELSIF NOT fail_check1(NEW.studid, new.sch_name) THEN
RAISE NOTICE 'DECLINED:FAIL_CHECK';
ELSIF NOT semunit_check1(NEW.studid) THEN
RAISE NOTICE 'DECLINED:UNIT_CHECK';
ELSIF NOT gwa_check(NEW.studid, NEW.sch_name) THEN
RAISE NOTICE 'DECLINED:GPA_CHECK';
ELSE
NEW.gpa := gwa_calc(NEW.studid);
RETURN NEW;
END IF;
RETURN NULL;
END;
$func$ LANGUAGE plpgsql;
The INSERT
happens automatically as long as you RETURN NEW
. Don't duplicate it, that would result in an endless loop.
I suggest you invert the logic of your tests, so you can simplify and drop all the negations. If you don't need all those notices, this can be simplified further.