Re: returning a record from a function?

Поиск
Список
Период
Сортировка
От Roberto Mello
Тема Re: returning a record from a function?
Дата
Msg-id 20020225145957.GC24707@cc.usu.edu
обсуждение исходный текст
Ответ на returning a record from a function?  ("Jon Obuchowski" <jon_obuchowski@terc.edu>)
Список pgsql-sql
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 fooWHERE 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


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Henry"
Дата:
Сообщение: callable statement support
Следующее
От: BOURIAUD
Дата:
Сообщение: About referential integrity.