using server side cursor

Поиск
Список
Период
Сортировка
От thomas veymont
Тема using server side cursor
Дата
Msg-id CAHcTkqqJxTFX7YanYCrfHiuMOfSp_Kt=SG7siAau6=CCJz6w_g@mail.gmail.com
обсуждение исходный текст
Ответы Re: using server side cursor  (Federico Di Gregorio <fog@dndg.it>)
Re: using server side cursor  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Список psycopg
hello,

I'm using pgsql cursors for making queries or large datasets.
To do this, my database already implements a plpgsql function that
return a cursor on some query.
(see http://www.postgresql.org/docs/9.0/static/plpgsql-cursors.html )

As shown in this doc, my database contains a function that
looks like this :

CREATE FUNCTION myfunction ( refcursor )  RETURNS refcursor AS '
BEGIN
    OPEN $1 FOR SELECT col FROM test;
    RETURN $1;
END;
' LANGUAGE plpgsql;

Then, from the db prompt, I am able to call the function
(thus creating a cursor), then fetch one row at a time :

BEGIN;
SELECT myfunction('mycursor');
  myfunction
-----------------------
 mycursor
(1 row)

FETCH mycursor;
(...)
FETCH mycursor;
COMMIT;

Now I want to do the same into the Python code -
naively I do something like:

mycursor.callproc ( "myfunction", [ "mycursor" ] )  # setup a cursor
in the db engine
mycursor.execute ( "fetch", [ "mycursor" ] ) # fetch row from this cursor
mycursor.fetchone()
(...)

but this returns an empty result.

I guess I'm doing it the wrong way. There's a doc in psycopg
about named cursors but I don't understand exactly how I should
follow it to tie to my problem. (that is : using my existing pgpsql function
that returns a cursor, then iterate on that cursor).

any suggestion ?

thanks
Tom

В списке psycopg по дате отправления:

Предыдущее
От: Daniele Varrazzo
Дата:
Сообщение: Re: Iterating through cur and cur.fetchone()
Следующее
От: Federico Di Gregorio
Дата:
Сообщение: Re: using server side cursor