X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 17019475ADE for ; Thu, 20 Feb 2003 08:01:36 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 61116-10 for ; Thu, 20 Feb 2003 08:01:24 -0500 (EST) Received: from mta02-svc.ntlworld.com (mta02-svc.ntlworld.com [62.253.162.42]) by postgresql.org (Postfix) with ESMTP id BB38C47580B for ; Thu, 20 Feb 2003 07:59:42 -0500 (EST) Received: from [80.2.138.220] by mta02-svc.ntlworld.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20030220125945.XVGW4529.mta02-svc.ntlworld.com@[80.2.138.220]> for ; Thu, 20 Feb 2003 12:59:45 +0000 From: "Graham Vickrage" To: Subject: pg_func problem Date: Thu, 20 Feb 2003 12:58:34 -0000 Message-ID: <007b01c2d8df$c9cdf5a0$6d00000a@GVICKRAGE> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.3416 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200302/463 X-Sequence-Number: 11861 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 ' DECLARE num INT4; BEGIN IF OLD.status = ''Complete'' AND NEW.status != ''Complete'' THEN --Invalid option RAISE EXCEPTION ''This is an invlid status change ''; ELSIF OLD.status = ''Pending'' THEN IF NEW.status = ''Complete'' THEN UPDATE supplier_order_detail SET 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'') AND NEW.status = ''Complete'' THEN RAISE EXCEPTION ''Invalid change of status''; END IF; RETURN NEW; END;' LANGUAGE 'plpgsql'; Thanks in advance. Graham