pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: student23 <student23@o2.pl>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Set of cursors from database
Date: Mon, 11 Sep 2006 12:42:54 -0500 (EST)
Message-ID: <Pine.BSO.4.63.0609111241020.8730@leary2.csoft.net> (raw)
In-Reply-To: <1e1007b7.39dcdb0b.44f6e63c.9067e@o2.pl>
References: <1e1007b7.39dcdb0b.44f6e63c.9067e@o2.pl>



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




view thread (2+ messages)

Message-ID: <Pine.BSO.4.63.0609111241020.8730@leary2.csoft.net>
Permalink:  ../Pine.BSO.4.63.0609111241020.8730@leary2.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.63.0609111241020.8730@leary2.csoft.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: books@ejurka.com, student23@o2.pl
  Subject: Re: Set of cursors from database
  In-Reply-To: <Pine.BSO.4.63.0609111241020.8730@leary2.csoft.net>
  References: <1e1007b7.39dcdb0b.44f6e63c.9067e@o2.pl> <Pine.BSO.4.63.0609111241020.8730@leary2.csoft.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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