Unix Technical Forum

8.1 OUT params returning more than one row question

This is a discussion on 8.1 OUT params returning more than one row question within the pgsql Hackers forums, part of the PostgreSQL category; --> Hi, I have been playing around with 8.1(it's very nice by the way) and was trying to get OUT ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 05:30 AM
Tony Caduto
 
Posts: n/a
Default 8.1 OUT params returning more than one row question

Hi,
I have been playing around with 8.1(it's very nice by the way) and was
trying to get OUT params to return more than 1 row.

I came up with the function below, and it does work, however I had to
declare another record to use in the FOR ..IN loop.

From my reading of the docs the out params create a record type
automaticly and my question is how can I use this automaticly created
record in the
FOR loop? It does not seem right that I have to create another record
type and then copy the row values to the out parms.

CREATE OR REPLACE FUNCTION test_func9(out firstname varchar, out
lastname varchar)
RETURNS SETOF record AS
$BODY$
Declare
row record;
BEGIN
for row in select null,description from common.common_groups
loop
firstname = row.description;
lastname = '';
RETURN NEXT;
end loop;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;

Thanks,

Tony

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 05:30 AM
Alvaro Herrera
 
Posts: n/a
Default Re: 8.1 OUT params returning more than one row question

On Wed, Aug 31, 2005 at 11:27:39AM -0500, Tony Caduto wrote:

Hi,

> I came up with the function below, and it does work, however I had to
> declare another record to use in the FOR ..IN loop.
>
> From my reading of the docs the out params create a record type
> automaticly and my question is how can I use this automaticly created
> record in the FOR loop? It does not seem right that I have to create
> another record type and then copy the row values to the out parms.


The record that you are not supposed to declare is the output record,
i.e. you don't have to use CREATE TYPE, use a table type, or describe
the anonymous record in the SELECT statement. Of course, in PL/pgSQL
you need a variable to do the FOR ... LOOP.

Your example works fine for me. What exactly were you expecting?

--
Alvaro Herrera -- Valdivia, Chile Architect, www.EnterpriseDB.com
"Escucha y olvidarás; ve y recordarás; haz y entenderás" (Confucio)

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:00 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com