From: | Roberto Mello <rmello(at)cc(dot)usu(dot)edu> |
---|---|
To: | Jon Obuchowski <jon_obuchowski(at)terc(dot)edu> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: returning a record from a function? |
Date: | 2002-02-25 14:59:57 |
Message-ID: | 20020225145957.GC24707@cc.usu.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 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
From | Date | Subject | |
---|---|---|---|
Next Message | BOURIAUD | 2002-02-25 15:01:49 | About referential integrity. |
Previous Message | Roberto Mello | 2002-02-25 14:55:12 | Re: PLPGSQL func. defn. for returning resultset? |