pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gary Stainburn <gary.stainburn@ringways.co.uk>
To: pgsql-sql@postgresql.org
Subject: create function problem
Date: Thu, 30 Dec 2010 16:26:00 +0000
Message-ID: <201012301626.00240.gary.stainburn@ringways.co.uk> (raw)

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 



view thread (8+ messages)  latest in thread

Message-ID: <201012301626.00240.gary.stainburn@ringways.co.uk>
Permalink:  ../201012301626.00240.gary.stainburn@ringways.co.uk/
Also on:    postgresql.org/message-id/201012301626.00240.gary.stainburn@ringways.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gary.stainburn@ringways.co.uk
  Subject: Re: create function problem
  In-Reply-To: <201012301626.00240.gary.stainburn@ringways.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox