Function returning record
Function returning record
От:
alla@sergey.com (Alla)
Дата:
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
Re: Function returning record
От:
"Thalis A. Kalfigopoulos" <thalis@cs.pitt.edu>
Дата:
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
>