Thread: Help with functions

Help with functions

From
"Patrick Bye (WFF)"
Date:
I'm having trouble trying to create a function.  I'm new to functions and
I'm trying to figure them out but I can't even get something simple like
this to work.  I believe I should be able to do 'SELECT getprice('text1',
'text2', 'text3', 'text4') as price' but all I get in PGAdmin tool is syntax
error near getprice.  Is my SELECT statement wrong or my function.  I did a
createlang on plpgsql before I started.  I'm running 7.2.4.

CREATE FUNCTION getprice(text, text, text, text) RETURNS float8 AS 'DECLARE
   v_itemnum ALIAS FOR $1;
   v_custnum ALIAS FOR $2;
   v_pcid ALIAS FOR $3;
   v_branch ALIAS FOR $4;
BEGIN
RETURN 0;
END getprice;

'  LANGUAGE 'plpgsql';



Patrick Bye
Programmer / Analyst
Westfair Foods Ltd.
pbye@westfair.ca
(403) 291-6538


Re: Help with functions

From
Brandon Craig Rhodes
Date:
"Patrick Bye (WFF)" <PBYE@Westfair.CA> writes:

> CREATE FUNCTION getprice(text, text, text, text) RETURNS float8 AS 'DECLARE
>    v_itemnum ALIAS FOR $1;
>    v_custnum ALIAS FOR $2;
>    v_pcid ALIAS FOR $3;
>    v_branch ALIAS FOR $4;
> BEGIN
> RETURN 0;
> END getprice;
> '  LANGUAGE 'plpgsql';

Try changing the `END getprice;' to just `END;' like the examples in
the manual.  Note that the error message should have pointed you to
the specific line in the function where this error lay (with lines
counting from the beginning of the function, not the file).

--
Brandon Craig Rhodes                         http://www.rhodesmill.org/brandon
Georgia Tech                                            brandon@oit.gatech.edu

Re: Help with functions

From
"Cristian Custodio"
Date:
Jast remove the name of the function alter END

wrong: END getprice;

ritgh: END;

Cristian

----- Original Message -----
From: "Patrick Bye (WFF)" <PBYE@Westfair.CA>
To: <pgsql-general@postgresql.org>
Sent: Monday, March 03, 2003 7:20 PM
Subject: [GENERAL] Help with functions


I'm having trouble trying to create a function.  I'm new to functions and
I'm trying to figure them out but I can't even get something simple like
this to work.  I believe I should be able to do 'SELECT getprice('text1',
'text2', 'text3', 'text4') as price' but all I get in PGAdmin tool is syntax
error near getprice.  Is my SELECT statement wrong or my function.  I did a
createlang on plpgsql before I started.  I'm running 7.2.4.

CREATE FUNCTION getprice(text, text, text, text) RETURNS float8 AS 'DECLARE
   v_itemnum ALIAS FOR $1;
   v_custnum ALIAS FOR $2;
   v_pcid ALIAS FOR $3;
   v_branch ALIAS FOR $4;
BEGIN
RETURN 0;
END getprice;

'  LANGUAGE 'plpgsql';



Patrick Bye
Programmer / Analyst
Westfair Foods Ltd.
pbye@westfair.ca
(403) 291-6538


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html