Re: starting on functions (with a bit more succes)

From: Odysseus <bart(dot)pietercil(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: starting on functions (with a bit more succes)
Date: 2011-07-06 21:57:49
Message-ID: 1309989469487-4559069.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

ok, one error fixed: do not combine declare with language 'sql'. When using
declare use 'plpgsql'

now this is accepted:

create FUNCTION createNewClient(clientName varchar, coreURL varchar,vs_ip
varchar, vs_db varchar, vs_connstring varchar, vs_usr_pw
varchar,lifespanUnitLV varchar, lifespan int2 DEFAULT null) RETURNS void
AS $BODY$
declare
aSerial uuid;
lifeSpanUnitPK bigint;

begin


SELECT INTO aSerial
newuuid();

select into lifeSpanUnitPK
tbl_typelistvalues.pkid
from tbl_typelistvalues
join tbl_typelists on tbl_typelistvalues.fk_typelist =
tbl_typelists.pkid
where listvalue = lifespanUnitLV AND typelistname =
'token_lifespan_units';

insert into
tbl_clients(vserver_userpw,vserver_ip,vserver_dbname,vserver_connectionstring,client_name,client_serial,client_core_url,token_lifespan,objptr_token_lifespan_unit)
values
(vs_usr_pw,vs_ip,vs_db,vs_connstring,clientName,aSerial,coreURL,lifespan,lifeSpanUnitPtr);

exception
when others then
raise ;
end;
$BODY$
LANGUAGE plpgsql
CALLED ON NULL INPUT
SECURITY INVOKER
IMMUTABLE;
--------------

Problem is not solved for this:

after BEGIN i would like to use this if then statement:
-----------------
if lifespanUnitLV = '4' then

end if
----------------
This returns an error: Error : ERROR: syntax error at or near "SELECT"
LINE 14: SELECT INTO aSerial
^

It must be something with the IF itself.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/starting-on-functions-with-little-succes-tp4557235p4559069.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Odysseus 2011-07-06 22:02:05 Re: starting on functions (with a bit more succes)
Previous Message Odysseus 2011-07-06 20:44:22 Re: starting on functions (with little succes)