pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Function returning record
2+ messages / 2 participants
[nested] [flat]

* Function returning record
@ 2001-06-07 18:53 Alla <alla@sergey.com>
  2001-06-12 20:42 ` Re: Function returning record Thalis A. Kalfigopoulos <thalis@cs.pitt.edu>
  0 siblings, 1 reply; 2+ messages in thread

From: alla@sergey.com @ 2001-06-07 18:53 UTC (permalink / raw)
  To: pgsql-general@postgresql.org.pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Function returning record
  2001-06-07 18:53 Function returning record Alla <alla@sergey.com>
@ 2001-06-12 20:42 ` Thalis A. Kalfigopoulos <thalis@cs.pitt.edu>
  0 siblings, 0 replies; 2+ messages in thread

From: Thalis A. Kalfigopoulos @ 2001-06-12 20:42 UTC (permalink / raw)
  To: Alla <alla@sergey.com>; +Cc: pgsql-general@postgresql.org

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
> 




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2001-06-12 20:42 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-07 18:53 Function returning record Alla <alla@sergey.com>
2001-06-12 20:42 ` Thalis A. Kalfigopoulos <thalis@cs.pitt.edu>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox