Re: Scrolling cursors in PL/PgSQL

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Dawid Kuroczko" <qnex42(at)gmail(dot)com>
Cc: "Postgres General" <pgsql-general(at)postgresql(dot)org>, pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Scrolling cursors in PL/PgSQL
Date: 2007-11-01 21:05:38
Message-ID: 162867790711011405x22b205afj9b89645e4f6a2174@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

On 01/11/2007, Dawid Kuroczko <qnex42(at)gmail(dot)com> wrote:
> Hello.
>
> Is there a way to scroll a cursor from within PL/PgSQL?
>
> I tried EXECUTE, but:
>
> ERROR: cannot manipulate cursors directly in PL/pgSQL
> HINT: Use PL/pgSQL's cursor features instead.
>
> The idea would be that PL/pgsql function would look
> through (all) query results, then rewind the cursor and
> finally return it.
>
> My fellow developers have created a function which run
> the (complex) query twice (first a count(*) on the result
> set, then return the row count and cursor to the results.
> Then they created a version which uses temporary
> table as a placeholder for the query results, and results
> count and a pointer to select * from tmp_table.
>
> Now I imagined a function which would open the cursor,
> MOVE FORWARD ALL, then MOVE ABSOLUTE 0;
> and return count and a cursor, yet it seems it won't work.
>
> Any other idea how to efficiently solve such a problem?
>

Hello

PostgreSQL 8.3 allows scrollable cursors in plpgsql

Regards
Pavel Stehule

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-11-01 21:11:33 Re: select random order by random
Previous Message Raymond O'Donnell 2007-11-01 21:02:42 Re: Scrolling cursors in PL/PgSQL

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2007-11-01 21:22:12 Re: Scrolling cursors in PL/PgSQL
Previous Message Raymond O'Donnell 2007-11-01 21:02:42 Re: Scrolling cursors in PL/PgSQL