X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 16008329E6C for ; Mon, 13 Sep 2004 16:40:01 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 71883-07 for ; Mon, 13 Sep 2004 15:39:51 +0000 (GMT) Received: from kelcomaine.com (linus.kelcomaine.com [208.34.185.140]) by svr1.postgresql.org (Postfix) with ESMTP id 7C95C329E6A for ; Mon, 13 Sep 2004 16:39:46 +0100 (BST) Received: from kelcomaine.com (localhost [127.0.0.1]) by kelcomaine.com (8.11.6/8.11.6) with SMTP id i8DFTYY28505; Mon, 13 Sep 2004 11:29:34 -0400 Date: Mon, 13 Sep 2004 15:29:34 -0000 To: "Leo Martin Orfei" , Subject: Re: problems returning a resultset from a function From: "Jim Wilson" X-Mailer: TWIG 2.7.7 Message-ID: In-Reply-To: <20040904160747.66889.qmail@web51806.mail.yahoo.com> Reply-To: jimw@kelcomaine.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/580 X-Sequence-Number: 65786 Leo Martin Orfei said: > hi. > > I have a problem with postgres functions. > I need return a resultset from a postgres function and > browse the resultset in a java app. > I try with this simple function: > > create function test() returns catalog.refcursor as' > declare aux refcursor; > BEGIN > OPEN aux FOR SELECT name, address FROM table; > RETURN aux; > END; > 'LANGUAGE 'plpgsql'; > My apologies if this has been responded to already as I am not currently reading pgsql-jdbc and the archive three days behind. AFAIK there isn't support for embedded work in jdbc, so it doesn't seem returning a cursor directly would help (well maybe there is a way...I don't know). In order to accomplish what I think you want to accomplish (which is to establish a jdbc resultset object from a stored function) I've done the following in the past: Create a pl/pgsql function that returns a rowtype, DECLARED as follows: -- the "table" in the following refers to an existing table definition row table%rowtype; In the pl/pgsql script you have something like: -- return each row in the result set for row in SELECT name, address FROM table loop return next row; end loop; return; Then in java call this using just a regular statement object: // test() is the name of the stored function. rs = statement.executeQuery("select * from test()"); while (rs.next()) { ...code to browse/process the rows... } Note the above examples might have a typo or two...but that's the general idea. I have not used the stored procedure statement object as you did. Perhaps that would be more portable. Best, Jim -- Jim Wilson - IT Manager Kelco Industries PO Box 160 58 Main Street Milbridge, ME 04658 207-546-7989 - FAX 207-546-2791 http://www.kelcomaine.com