simple function syntax

Started by Culley Harrelsonabout 25 years ago7 messagesgeneral
Jump to latest
#1Culley Harrelson
culleyharrelson@yahoo.com

OK trying to write my first function and its blowing
up at compile. What's wrong with this:

CREATE FUNCTION test_function(int4) RETURNS int4 AS '
DECLARE
test ALIAS FOR $1;
BEGIN
RETURN test;
END;
' LANGUAGE 'plpgsql';

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/

#2Robert B. Easter
reaster@comptechnews.com
In reply to: Culley Harrelson (#1)
Re: simple function syntax

Load the procedural language from the shell:

createlang plsql <dbname>

On Friday 26 January 2001 00:55, Culley Harrelson wrote:

OK trying to write my first function and its blowing
up at compile. What's wrong with this:

CREATE FUNCTION test_function(int4) RETURNS int4 AS '
DECLARE
test ALIAS FOR $1;
BEGIN
RETURN test;
END;
' LANGUAGE 'plpgsql';

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/

--
-------- Robert B. Easter reaster@comptechnews.com ---------
-- CompTechNews Message Board http://www.comptechnews.com/ --
-- CompTechServ Tech Services http://www.comptechserv.com/ --
---------- http://www.comptechnews.com/~reaster/ ------------

#3Culley Harrelson
culleyharrelson@yahoo.com
In reply to: Robert B. Easter (#2)
Re: simple function syntax

I ran createlang successfully and I'm still getting
compile errors on basic plpgsql functions (sql
functions work).I'm assuming I have to do something
like:

create trusted procedural language plpgsql
handler = ????

do I need to write a handler function for plpgsql?

Boy this is making me feel really lame :)

Culley

--- "Robert B. Easter" <reaster@comptechnews.com>
wrote:

Load the procedural language from the shell:

createlang plsql <dbname>

On Friday 26 January 2001 00:55, Culley Harrelson
wrote:

OK trying to write my first function and its

blowing

up at compile. What's wrong with this:

CREATE FUNCTION test_function(int4) RETURNS int4

AS '

DECLARE
test ALIAS FOR $1;
BEGIN
RETURN test;
END;
' LANGUAGE 'plpgsql';

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great

prices.

http://auctions.yahoo.com/

--
-------- Robert B. Easter reaster@comptechnews.com
---------
-- CompTechNews Message Board
http://www.comptechnews.com/ --
-- CompTechServ Tech Services
http://www.comptechserv.com/ --
---------- http://www.comptechnews.com/~reaster/

------------

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Culley Harrelson (#3)
Re: simple function syntax

Culley Harrelson <culleyharrelson@yahoo.com> writes:

I ran createlang successfully and I'm still getting
compile errors on basic plpgsql functions (sql
functions work).I'm assuming I have to do something
like:

create trusted procedural language plpgsql
handler = ????

No, createlang should've done that for you.

What do you get from "select * from pg_language" ?

Also, it would help if you mentioned the exact error message
you're getting.

regards, tom lane

#5Robert B. Easter
reaster@comptechnews.com
In reply to: Culley Harrelson (#3)
Re: simple function syntax

On Saturday 27 January 2001 20:12, Culley Harrelson wrote:

Boy this is making me feel really lame :)

:) What are the error messages and the version of Postgres? Someone should be
able to help you more if you post more information.

--
-------- Robert B. Easter reaster@comptechnews.com ---------
-- CompTechNews Message Board http://www.comptechnews.com/ --
-- CompTechServ Tech Services http://www.comptechserv.com/ --
---------- http://www.comptechnews.com/~reaster/ ------------

#6Culley Harrelson
culleyharrelson@yahoo.com
In reply to: Robert B. Easter (#5)
Re: simple function syntax

ok the complete error is:

----------------
NOTICE: plpgsql: ERROR during compile of add_one
near line 1
"RROR: parse error near "
----------------

I was trying to select the add_one function in the
documentation.

In the pg_language table I have entries for internal,
c, sql and plpgsql. The plpgsql record reads:

lanname = plpgsql
lanispl = t
lanpltrusted = t
pancallfoid = 19488
lancompiler = PL/pgSQL

the createlang statement I used was:

createlang plpgsql db_name -L /usr/local/pgsql/lib

this is on a new install of slackware 7.1

Culley

--- Tom Lane <tgl@sss.pgh.pa.us> wrote:

Culley Harrelson <culleyharrelson@yahoo.com> writes:

I ran createlang successfully and I'm still

getting

compile errors on basic plpgsql functions (sql
functions work).I'm assuming I have to do

something

like:

create trusted procedural language plpgsql
handler = ????

No, createlang should've done that for you.

What do you get from "select * from pg_language" ?

Also, it would help if you mentioned the exact error
message
you're getting.

regards, tom lane

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Culley Harrelson (#6)
Re: simple function syntax

Culley Harrelson <culleyharrelson@yahoo.com> writes:

ok the complete error is:
----------------
NOTICE: plpgsql: ERROR during compile of add_one
near line 1
"RROR: parse error near "
----------------

Oh, that old thing...

Save the script with a less Microsofty editor, one that thinks newlines
are \n not \r\n. The plpgsql parser doesn't think \r is whitespace.

(Yes, it's been changed for 7.1)

regards, tom lane