Re: composite type and assignment in plpgsql

From: Ron St-Pierre <rstpierre(at)syscor(dot)com>
To: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: composite type and assignment in plpgsql
Date: 2004-04-27 17:12:13
Message-ID: 408E946D.6010103@syscor.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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 response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron St-Pierre 2004-04-27 17:18:56 Re: composite type and assignment in plpgsql
Previous Message Frank Finner 2004-04-27 17:08:12 Re: Installation Postgresql