Thread: pg_func problem

pg_func problem

From
"Graham Vickrage"
Date:
Hi All,

I am trying to use the function below, it works fine on my dev server
running 7.2.3 but does not work on my production server running 7.1.2.
(both on linux)

Would anyone be able to shed some light on why this is the case.

The error I get is: 
ERROR during compile of 'change_sup_ord_status' near line 19
parse error at or near "IF"

I am running the following query against the function below: -

Query: UPDATE supplier_order SET status = 'Pending' where id = 2003;


CREATE FUNCTION change_sup_ord_status () RETURNS OPAQUE AS '
DECLAREnum INT4;
BEGINIF OLD.status = ''Complete'' AND NEW.status != ''Complete'' THEN    --Invalid option    RAISE EXCEPTION ''This is
aninvlid status change '';ELSIF OLD.status = ''Pending''  THEN    IF NEW.status = ''Complete'' THEN        UPDATE
supplier_order_detailSET
 
status=''Complete'' WHERE supplier_order_id = OLD.id AND
status=''Pending'';    ELSIF NEW.status = ''VOID'' OR NEW.status = ''Saved''
THEN        SELECT count(*) INTO num FROM
supplier_order_detail WHERE supplier_order_id = OLD.id AND status =
''Complete'';                IF num > 0 THEN             RAISE EXCEPTION ''Invalid change of
status, some of the order has already been entered into stock'';        END IF;    END IF;ELSIF (OLD.status = ''VOID'')
ANDNEW.status = ''Complete'' THEN    RAISE EXCEPTION ''Invalid change of status'';END IF;
 
RETURN NEW;
END;' LANGUAGE 'plpgsql';


Thanks in advance.

Graham