Re: Question aboud #80 - itersize in cursor dic

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Kryklia Alex <kryklia(at)gmail(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: Question aboud #80 - itersize in cursor dic
Date: 2012-05-16 10:48:06
Message-ID: CA+mi_8a5NNCmJwtVG0LaPOwXqtzg3EemZhd6L5caxqfJgpS2nA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Tue, May 15, 2012 at 5:59 PM, Kryklia Alex <kryklia(at)gmail(dot)com> wrote:
> Hi!
> Thank for great library.
> Dear group users, please help me with understanding of situation.

[...]

> and now iterating over named cursor return 1 row, not many
>
> Please help, should i use cursor.fetchmany instead?
> Or how use itersize? (Why itersize not working)

Hi Alex, sorry I may have not understood you but everything seems
working fine for me: iterating over a named dict cursor fetches
itersize at time. An explicit reference to itersize has been dropped
from extras.py because __iter__ now calls into the superclass'
__iter__ instead of fetchmany. Testing with debug enabled with psycopg
2.4.5, and including the relevant debug info:

In [3]: cnn = psycopg2.connect('')
In [4]: cur = cnn.cursor('test', cursor_factory=psycopg2.extras.DictCursor)
In [5]: cur.execute("select generate_series(1,20)")
[13211] DECLARE "test" CURSOR WITHOUT HOLD FOR select generate_series(1,20)

In [6]: for i in cur: print i
...:
[13211] FETCH FORWARD 2000 FROM "test"
[1]
[2]
[3]
[...]

It has fetched the default itersize records. Testing with a different
cursor class, non-default itersize:

In [16]: cur = cnn.cursor('test', cursor_factory=psycopg2.extras.RealDictCursor)
In [17]: cur.itersize = 2
In [18]: cur.execute("select generate_series(1,5)")
[13211] DECLARE "test" CURSOR WITHOUT HOLD FOR select generate_series(1,5)

In [19]: for i in cur: print i
....:
[13211] FETCH FORWARD 2 FROM "test"
{'generate_series': 1}
{'generate_series': 2}
[13211] FETCH FORWARD 2 FROM "test"
{'generate_series': 3}
{'generate_series': 4}
[13211] FETCH FORWARD 2 FROM "test"
{'generate_series': 5}
[13211] FETCH FORWARD 2 FROM "test"

In [20]:

This is the expected behaviour for me. If there is any problem I have
not understood please include a test case.

Thank you,

-- Daniele

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Kryklia Alex 2012-05-16 12:45:23 Fwd: Question aboud #80 - itersize in cursor dic
Previous Message Federico Di Gregorio 2012-05-16 09:23:48 Re: Question aboud #80 - itersize in cursor dic