On Tue, May 15, 2012 at 5:59 PM, Kryklia Alex <kryklia@gmail.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