returning a record from a function?

From: "Jon Obuchowski" <jon_obuchowski(at)terc(dot)edu>
To: pgsql-sql(at)postgresql(dot)org
Subject: returning a record from a function?
Date: 2002-02-25 03:33:40
Message-ID: 85256B6B.00121D32.00@procyon.terc.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2002-02-25 03:49:56 Re: returning a record from a function?
Previous Message Otis Gospodnetic 2002-02-24 20:18:54 PLPGSQL func. defn. for returning resultset?