Re: Function returning record

From: "Thalis A(dot) Kalfigopoulos" <thalis(at)cs(dot)pitt(dot)edu>
To: Alla <alla(at)sergey(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Function returning record
Date: 2001-06-12 20:42:05
Message-ID: Pine.LNX.4.21.0106121633180.19889-100000@aluminum.cs.pitt.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

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(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Arcady Genkin 2001-06-12 20:42:31 PHP's pg_connect() and non-standard location of the socket (was: REPOST: redefining location of the socket file /tmp/.s.PGSQL.5432)
Previous Message Gregory Wood 2001-06-12 20:39:38 Re: WAS: PostgreSQL Replication Server? IS: Zend comparison

Browse pgsql-sql by date

  From Date Subject
Next Message Thalis A. Kalfigopoulos 2001-06-12 20:55:56 Re: Please help! Functions passing records between them
Previous Message Tim Barnard 2001-06-12 20:10:41 Re: Re: [SQL] maximum number of rows in table - what about oid limits?