pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jon Obuchowski <jon_obuchowski@terc.edu>
To: pgsql-sql@postgresql.org
Subject: returning a record from a function?
Date: Sun, 24 Feb 2002 22:33:40 -0500
Message-ID: <85256B6B.00121D32.00@procyon.terc.edu> (raw)

Hello,

I am interested in returning complete records (based on existing table
structures) from a function; I know how to deal with record variables
_within_ a function (using PL/PGSQL), but am uncertain as how to instruct
the general CREATE FUNCTION syntax to return a recordset (versus a single
value corresponding to a simple or complex dataype).

My attempts to do so look like the following code (with table "foo"):

     CREATE FUNCTION get_newest_foo ()
     RETURNS foo AS '
          SELECT *
               FROM foo
                          WHERE foo_id =
                          (select MAX(foo_id) FROM foo);
     ' LANGUAGE 'sql';

this compiles and executes without warnings or exceptions - but this is the
result which I get:
     jono=> select get_newest_foo ();
     get_newest_foo
     -----------
         3393448
     (1 row)

I thought that this might be an oid (corresponding to the selected record),
but testing showed that this is not the case.

Any help with this is appreciated; if I am simply overlooking relevant
documentation I'd appreciate being pointed towards the relevant page.

thanks,
Jon





view thread (3+ messages)  latest in thread

Message-ID: <85256B6B.00121D32.00@procyon.terc.edu>
Permalink:  ../85256B6B.00121D32.00@procyon.terc.edu/
Also on:    postgresql.org/message-id/85256B6B.00121D32.00@procyon.terc.edu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jon_obuchowski@terc.edu
  Subject: Re: returning a record from a function?
  In-Reply-To: <85256B6B.00121D32.00@procyon.terc.edu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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