From: | Rory Campbell-Lange <rory(at)campbell-lange(dot)net> |
---|---|
To: | Henry Combrinck <henry(at)metroweb(dot)co(dot)za> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Passing RECORD variable from func1() to func2() |
Date: | 2004-09-07 10:02:27 |
Message-ID: | 20040907100227.GB16127@campbell-lange.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Howzit Henry
On 06/09/04, Henry Combrinck (henry(at)metroweb(dot)co(dot)za) wrote:
> Essentially, I would like to pass a RECORD variable from one function to
> another using plpgsql:
You may want to have a look at using cursor references.
For instance:
CREATE FUNCTION use_cursors ( INTEGER ) RETURNS INTEGER AS '
DECLARE
ref_cursors REFCURSOR;
total INTEGER := 0;
BEGIN
curs := get_ref_cursor_from_other_function ( $1 );
total := use_curs_to_do_totaling_function ( ref_cursors );
RETURN total;
END;
' LANGUAGE 'plpgsql';
CREATE FUNCTION get_ref_cursor_from_other_function ( INTEGER ) RETURNS REFCURSOR AS '
DECLARE
next_val REFCURSOR;
BEGIN
OPEN next_val FOR
SELECT * FROM mytable WHERE intcol = $1;
RETURN ( next_val);
END;
' LANGUAGE 'plpgsql';
CREATE FUNCTION use_curs_to_do_totaling_function ( REFCURSOR ) RETURNS INTEGER AS '
DECLARE
myrow mytable%rowtype;
total INTEGER := 0;
next_val ALIAS for $1;
BEGIN
LOOP
FETCH next_val INTO myrow;
EXIT WHEN NOT FOUND;
total := total + myrow.<somecolval>;
END LOOP;
RETURN (total);
END;
' LANGUAGE 'plpgsql';
--
Rory Campbell-Lange
<rory(at)campbell-lange(dot)net>
<www.campbell-lange.net>
From | Date | Subject | |
---|---|---|---|
Next Message | Paramveer.Singh | 2004-09-07 10:12:02 | postgres 8 performance |
Previous Message | Rory Campbell-Lange | 2004-09-07 09:44:37 | Re: Passing RECORD variable from func1() to func2() |