Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 795941337B43 for ; Thu, 30 Dec 2010 13:29:24 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 91151-06 for ; Thu, 30 Dec 2010 17:29:16 +0000 (UTC) X-Greylist: delayed 01:03:10.412269 by SQLgrey-1.7.6 Received: from mail.ringways.co.uk (hub.ringways.co.uk [77.86.27.30]) by mail.postgresql.org (Postfix) with ESMTP id B9005133798E for ; Thu, 30 Dec 2010 13:29:15 -0400 (AST) Received: from eddie.ringways.co.uk ([10.1.1.115]) by mail.ringways.co.uk with esmtp (Exim 4.69) (envelope-from ) id 1PYLK8-0006np-W7 for pgsql-sql@postgresql.org; Thu, 30 Dec 2010 16:25:58 +0000 From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: create function problem Date: Thu, 30 Dec 2010 16:26:00 +0000 User-Agent: KMail/1.9.10 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201012301626.00240.gary.stainburn@ringways.co.uk> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201012/103 X-Sequence-Number: 34939 Hi folks, I'm writing my first plpsql function in ages and I'm going blind trying to see why it won't create. The error message and the code are below. I'm guessing it's something blindingly obvious, but can someone please point it out to me. ta Gary The actual line number is the LANGUAGE line at the end of the file. goole=# \i project_delivery_date.sql psql:project_delivery_date.sql:42: ERROR: syntax error at or near ";" LINE 37: END; ^ goole=# \q [root@stan t-cards]# cat project_delivery_date.sql -- vim: ft=sql et ai ic -- -- project_delivery_date() - project delivery date from existing dates CREATE FUNCTION project_delivery_date(date,date,date,date) RETURNS date AS $$ DECLARE eta_dealer ALIAS FOR $1; eta_customer ALIAS FOR $2; req_date ALIAS FOR $3; act_date ALIAS FOR $4; eta date; BEGIN IF act_date IS NOT NULL THEN return act_date; END IF; IF eta_dealer IS NOT NULL AND eta_customer IS NULL THEN eta := eta_dealer; ELSE IF eta_dealer IS NULL AND eta_customer IS NOT NULL THEN eta := eta_customer; ELSE IF eta_dealer IS NULL AND eta_customer IS NULL THEN eta := NULL; ELSE IF eta_dealer > eta_customer THEN eta := eta_dealer; ELSE eta := eta_customer; END IF; IF eta IS NOT NULL AND req_date IS NULL THEN RETURN eta; END IF; IF eta IS NULL AND req_date IS NOT NULL THEN RETURN req_date; END IF; IF eta IS NULL AND req_date IS NULL THEN RETURN NULL; END IF; IF eta > req_date THEN RETURN eta; END IF; RETURN req_date; END; $$ LANGUAGE 'plpgsql'; [root@stan t-cards]# -- Gary Stainburn I.T. Manager Ringways Garages http://www.ringways.co.uk