pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedSet of cursors from database
2+ messages / 2 participants
[nested] [flat]
* Set of cursors from database
@ 2006-08-31 13:38 student23 <student23@o2.pl>
0 siblings, 1 reply; 2+ messages in thread
From: student23 @ 2006-08-31 13:38 UTC (permalink / raw)
To: pgsql-jdbc
Hi,
I'm want to retrieve a set of cursors but with only one call to database. I was wondering about how to write such function in postgres and get the results in java.
Have anyone some experience in doing such thing??
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Set of cursors from database
@ 2006-09-11 17:42 Kris Jurka <books@ejurka.com>
parent: student23 <student23@o2.pl>
0 siblings, 0 replies; 2+ messages in thread
From: Kris Jurka @ 2006-09-11 17:42 UTC (permalink / raw)
To: student23 <student23@o2.pl>; +Cc: pgsql-jdbc
On Thu, 31 Aug 2006, student23 wrote:
> I'm want to retrieve a set of cursors but with only one call to
> database. I was wondering about how to write such function in postgres
> and get the results in java.
>
There are two approaches to doing this. You can either return a SETOF
refcursor or you can return multiple refcursors as OUT parameters.
Building on the example from the documentation for how to call this from
java the two following functions should be helpful:
http://jdbc.postgresql.org/documentation/81/callproc.html#callproc-resultset-refcursor
CREATE FUNCTION setofcursors() RETURNS SETOF refcursor AS '
DECLARE
curs1 refcursor;
curs2 refcursor;
BEGIN
OPEN curs1 FOR SELECT 1;
RETURN NEXT curs1;
OPEN curs2 FOR SELECT 2;
RETURN NEXT curs2;
RETURN;
END;
' LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION outcursors(curs1 OUT refcursor, curs2 OUT
refcursor) AS '
BEGIN
OPEN curs1 FOR SELECT 1;
OPEN curs2 FOR SELECT 2;
RETURN;
END;
' LANGUAGE plpgsql;
Kris Jurka
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2006-09-11 17:42 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-08-31 13:38 Set of cursors from database student23 <student23@o2.pl>
2006-09-11 17:42 ` Kris Jurka <books@ejurka.com>
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