create function syntax error

Started by gustavo halperinover 19 years ago4 messagesgeneral
Jump to latest
#1gustavo halperin
ggh.develop@gmail.com

Hello

I Always get "syntax error" for every function that I try to create, for
example:
mydb'>create or replace function f_sum () returns void as '
mydb'> select 2+2;
mydb'> ' LANGUAGE plpgsql;
ERROR: syntax error at or near "select" at character 56
LINE 2: select 2+2;
^

What its the problem ??
Thank you,
Gustavo

#2Andreas Kretschmer
akretschmer@spamfence.net
In reply to: gustavo halperin (#1)
Re: create function syntax error

gustavo halperin <ggh.develop@gmail.com> schrieb:

Hello

I Always get "syntax error" for every function that I try to create, for
example:
mydb'>create or replace function f_sum () returns void as '
mydb'> select 2+2;
mydb'> ' LANGUAGE plpgsql;
ERROR: syntax error at or near "select" at character 56
LINE 2: select 2+2;
^

What its the problem ??

Several:
- wrong quotation, either with '' or with dollar-quote
- no 'begin'
- no 'end;'

Please read the docu:
http://www.postgresql.org/docs/8.1/interactive/plpgsql.html

There are many examples, for instance:
http://www.postgresql.org/docs/8.1/interactive/plpgsql-structure.html

HTH, Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknow)
Kaufbach, Saxony, Germany, Europe. N 51.05082�, E 13.56889�

#3Shoaib Mir
shoaibmir@gmail.com
In reply to: gustavo halperin (#1)
Re: create function syntax error

You are missing the BEGIN and END section. Make your function like this:

CREATE OR REPLACE FUNCTION f_sum() RETURNS void AS '
BEGIN
select 2+2;
END;
' LANGUAGE plpgsql;

Thanks,
--
Shoaib Mir
EnterpriseDB (www.enterprisedb.com)

On 7/30/06, gustavo halperin <ggh.develop@gmail.com> wrote:

Hello

I Always get "syntax error" for every function that I try to create, for
example:
mydb'>create or replace function f_sum () returns void as '
mydb'> select 2+2;
mydb'> ' LANGUAGE plpgsql;
ERROR: syntax error at or near "select" at character 56
LINE 2: select 2+2;
^

What its the problem ??
Thank you,
Gustavo

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

--
Shoaib Mir
EnterpriseDB (www.enterprisedb.com)

#4Andreas Kretschmer
akretschmer@spamfence.net
In reply to: Andreas Kretschmer (#2)
Re: create function syntax error

Andreas Kretschmer <akretschmer@spamfence.net> schrieb:

gustavo halperin <ggh.develop@gmail.com> schrieb:

Hello

I Always get "syntax error" for every function that I try to create, for
example:
mydb'>create or replace function f_sum () returns void as '
mydb'> select 2+2;
mydb'> ' LANGUAGE plpgsql;
ERROR: syntax error at or near "select" at character 56
LINE 2: select 2+2;
^

What its the problem ??

Several:
- wrong quotation, either with '' or with dollar-quote

Uhm, sorry. Error from me. The single quote after the 'as' is oray.

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknow)
Kaufbach, Saxony, Germany, Europe. N 51.05082�, E 13.56889�