Search Postgresql Archives

Re: composite type and assignment in plpgsql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ron St-Pierre wrote:

Ivan Sergio Borgonovo wrote:

what's wrong with this?

create type tSession
    as ( ty_found boolean, ty_Session char(32) );

create or replace function GetSessionID( integer )
    returns tSession as '
declare
    thisSession tSession;
begin
    --HERE!!!
    thisSession := ( ''t'', md5( now( ) || rand( ) ) );

- md5 takes TEXT as an argument, not a numeric type
- assign each variable of type tSession to its corresponding value:
thisSession.ty_found := ''t'';
thisSession.ty_session := md5(CAST((now( )) AS TEXT));
I haven't looked up the rand() function, but you can see from this how you would cast it and now() to text.


    return thisSession;
end;
' language plpgsql;


thx



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




And then you can get the results:
  select * from getsessionid(1);
imperial=#  select * from getsessionid(1);
ty_found |            ty_session
----------+----------------------------------
t        | cf76cca2b562a0ead48d3eb3810f51cc
(1 row)


hth


Ron


In the above reply, I forgot to mention that you are not using the integer you are passing in as an argument. If you need it (rand()?) you'll have to declare it:
myInt ALIAS FOR $1;
or use it explicitly with just the name: $1


Ron


---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux