Re: Function returning record - Mailing list pgsql-general

From Thalis A. Kalfigopoulos
Subject Re: Function returning record
Date
Msg-id Pine.LNX.4.21.0106121633180.19889-100000@aluminum.cs.pitt.edu
Whole thread Raw
In response to Function returning record  (alla@sergey.com (Alla))
List pgsql-general
You can have the function return a record but still when you call it you need to pick only one of its fields :-/

CREATE FUNCTION lala(int4) RETURNS my_table AS 'SELECT * from my_table WHERE pkey= $1' LANGUAGE 'sql';

Let's say it returns the record: {first_name,last_name,id}={'koko','xaxa',100}

When you call it you have to select one of the attributes:

select first_name(lala(100)) as Fname;
   fname
------------
 koko
(1 row)



cheers,
thalis


On 7 Jun 2001, Alla wrote:

> Is it possible in PostgreSQL to write a function that would return a
> record type.
>
> What I need is something like this:
>
> create function my_func(varchar)
> return record as '
> declare
>    my_rec   record;
> begin
>    select null as field1, null as field2
>    into my_rec;
>
>    .... some processing to populate the actual values of the record
>
>    return my_rec;
> end;
> ' LANGUAGE 'plpgsql';
>
>
> I get the following when I try to compile this:
> NOTICE:  ProcedureCreate: return type 'record' is only a shell
>
> and following when I try to execute it (even though I am not sure how
> to execute this at all);
> ERROR:  fmgr_info: function 0: cache lookup failed
>
> Please help.
>
> Thanks a lot in advance
>
> Alla
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: stumped on view/rule/delete problem.
Next
From: Stacy Cornbread
Date:
Subject: Re: Accessing two differents database in a SELECT