Re: starting on functions (with a bit more succes) - Mailing list pgsql-novice

From Odysseus
Subject Re: starting on functions (with a bit more succes)
Date
Msg-id 1309989469487-4559069.post@n5.nabble.com
Whole thread Raw
In response to Re: starting on functions (with little succes)  (Odysseus <bart.pietercil@gmail.com>)
Responses Re: starting on functions (with a bit more succes)  (Odysseus <bart.pietercil@gmail.com>)
List 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.

pgsql-novice by date:

Previous
From: Odysseus
Date:
Subject: Re: starting on functions (with little succes)
Next
From: Odysseus
Date:
Subject: Re: starting on functions (with a bit more succes)