Returning multiple cursors from PL/PgSQL

Started by David Fetterover 21 years ago5 messagespatches
Jump to latest
#1David Fetter
david@fetter.org

Folks,

Please find attached an example that allows people to return multiple
named refcursors from a function. Big kudos to Kris Jurka for
figuring this out and pasting to rafb :)

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778

Remember to vote!

Attachments:

multiple_cursor.difftext/plain; charset=us-asciiDownload+28-0
#2David Fetter
david@fetter.org
In reply to: David Fetter (#1)
Re: Returning multiple cursors from PL/PgSQL

On Wed, Jan 12, 2005 at 09:33:30PM -0800, David Fetter wrote:

Folks,

Please find attached an example that allows people to return multiple
named refcursors from a function. Big kudos to Kris Jurka for
figuring this out and pasting to rafb :)

Oops. Joe Conway pointed out that this patch could be more succinct
and not create an essentially useless new type.

Please find attached the revised patch.

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778

Remember to vote!

Attachments:

multiple_cursor.difftext/plain; charset=us-asciiDownload+28-0
#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: David Fetter (#2)
Re: Returning multiple cursors from PL/PgSQL

David Fetter <david@fetter.org> writes:

Please find attached an example that allows people to return multiple
named refcursors from a function. Big kudos to Kris Jurka for
figuring this out and pasting to rafb :)

Oops. Joe Conway pointed out that this patch could be more succinct
and not create an essentially useless new type.

I think the example is pretty confusing, or at least not compelling,
since it's not clear to the reader why you'd go to all that trouble
to return two scalars. The cursors ought to return rowsets.
Maybe

+     OPEN $1 FOR SELECT * FROM table1;
+     RETURN NEXT $1;
+     OPEN $2 FOR SELECT * FROM table2;
+     RETURN NEXT $2;

regards, tom lane

#4David Fetter
david@fetter.org
In reply to: Tom Lane (#3)
Re: Returning multiple cursors from PL/PgSQL

On Thu, Jan 13, 2005 at 01:44:58PM -0500, Tom Lane wrote:

David Fetter <david@fetter.org> writes:

Please find attached an example that allows people to return multiple
named refcursors from a function. Big kudos to Kris Jurka for
figuring this out and pasting to rafb :)

Oops. Joe Conway pointed out that this patch could be more succinct
and not create an essentially useless new type.

I think the example is pretty confusing, or at least not compelling,
since it's not clear to the reader why you'd go to all that trouble
to return two scalars. The cursors ought to return rowsets.
Maybe

+     OPEN $1 FOR SELECT * FROM table1;
+     RETURN NEXT $1;
+     OPEN $2 FOR SELECT * FROM table2;
+     RETURN NEXT $2;

regards, tom lane

Good point. Next patch attached :)

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778

Remember to vote!

Attachments:

multiple_cursor.difftext/plain; charset=us-asciiDownload+28-0
#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: David Fetter (#4)
Re: Returning multiple cursors from PL/PgSQL

David Fetter <david@fetter.org> writes:

Please find attached an example that allows people to return multiple
named refcursors from a function. Big kudos to Kris Jurka for
figuring this out and pasting to rafb :)

Applied the latest version of this.

regards, tom lane