Received: from brasileiro.net (slxwy.dorms.usu.edu [129.123.236.160]) by postgresql.org (Postfix) with ESMTP id 5E4184768CA for ; Mon, 25 Feb 2002 09:59:58 -0500 (EST) Received: from roberto by brasileiro.net with local (Exim 3.34 #1 (Debian)) id 16fMbd-0006cP-00; Mon, 25 Feb 2002 07:59:57 -0700 Date: Mon, 25 Feb 2002 07:59:57 -0700 From: Roberto Mello To: Jon Obuchowski Cc: pgsql-sql@postgresql.org Subject: Re: returning a record from a function? Message-ID: <20020225145957.GC24707@cc.usu.edu> References: <85256B6B.00121D32.00@procyon.terc.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <85256B6B.00121D32.00@procyon.terc.edu> User-Agent: Mutt/1.3.27i X-Archive-Number: 200202/355 X-Sequence-Number: 6777 On Sun, Feb 24, 2002 at 10:33:40PM -0500, Jon Obuchowski wrote: > > 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'; In the case above, wouldn't it be better if implemented as a VIEW? CREATE VIEW newest_foo AS SELECT * FROM foo WHERE foo_id = (select MAX(foo_id) FROM foo); SELECT * FROM newest_foo; > Any help with this is appreciated; if I am simply overlooking relevant > documentation I'd appreciate being pointed towards the relevant page. I think you're looking for the "setof" return type for SQL functions? See the CREATE FUNCTION reference. Also, I just sent a reply about returning rows from non-SQL functions that you might be interested in. -Roberto -- +----| http://fslc.usu.edu/ USU Free Software & GNU/Linux Club |------+ Roberto Mello - Computer Science, USU - http://www.brasileiro.net/ http://www.sdl.usu.edu/ - Space Dynamics Lab, Developer */ \* <- Tribbles having a swordfight