pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Roberto Mello <rmello@cc.usu.edu>
To: Jon Obuchowski <jon_obuchowski@terc.edu>
Cc: pgsql-sql@postgresql.org
Subject: Re: returning a record from a function?
Date: Mon, 25 Feb 2002 07:59:57 -0700
Message-ID: <20020225145957.GC24707@cc.usu.edu> (raw)
In-Reply-To: <85256B6B.00121D32.00@procyon.terc.edu>
References: <85256B6B.00121D32.00@procyon.terc.edu>

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



view thread (3+ messages)

Message-ID: <20020225145957.GC24707@cc.usu.edu>
Permalink:  ../20020225145957.GC24707@cc.usu.edu/
Also on:    postgresql.org/message-id/20020225145957.GC24707@cc.usu.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: rmello@cc.usu.edu, jon_obuchowski@terc.edu
  Subject: Re: returning a record from a function?
  In-Reply-To: <20020225145957.GC24707@cc.usu.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