Re: Cursor Example Needed

From: Perry Smith <pedzsan(at)gmail(dot)com>
To: John R Pierce <pierce(at)hogranch(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Cursor Example Needed
Date: 2013-10-28 23:36:34
Message-ID: 59EE49D1-B6E2-45FE-A594-F46EDE152B17@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Oct 28, 2013, at 6:13 PM, John R Pierce <pierce(at)hogranch(dot)com> wrote:

> On 10/28/2013 3:58 PM, Adrian Klaver wrote:
>> The docs do a good job of illustrating:
>>
>> http://www.postgresql.org/docs/9.3/interactive/plpgsql-cursors.html
>
> thats for cursors created within a plpgsql function.
>
> I think what the OP wants is a top level cursor, which is a different thing...
>
> see
> http://www.postgresql.org/docs/current/static/sql-declare.html
> http://www.postgresql.org/docs/current/static/sql-fetch.html
> http://www.postgresql.org/docs/current/static/sql-close.html
>
> the fetch page shows an example of the complete usage in the context of a database transaction.

Thank you to Merlin. I now understand better where my confusion was.

John:

Those examples are great except there is no way that I know of to loop on
the "top level" as you call it. I'm trying to do something that I can give to
psql which will loop through the entire set that is produced.

I came across the FOR-IN loop but that needs a function. But as Merlin
points out, the function is on the server side and I need the loop on the
client side.

Perhaps the

\set FETCH_COUNT 500000

solution that Merln point out originally is the only choice.

I feel like I've learned a lot even though it might not have been what
I was originally trying to learn :-)

Thank you again,
Perry

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2013-10-28 23:50:10 Re: Cursor Example Needed
Previous Message Gregory Haase 2013-10-28 23:17:34 json datatype and table bloat?