Skip site navigation (1) Skip section navigation (2)

Fwd: Question aboud #80 - itersize in cursor dic

From: Kryklia Alex <kryklia(at)gmail(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Fwd: Question aboud #80 - itersize in cursor dic
Date: 2012-05-16 12:45:23
Message-ID: CAGv7O6PdOnWHuPjXGYstwHVur-BeLHPsP0E6h_45Pj2QT+NFBQ@mail.gmail.com (view raw or flat)
Thread:
Lists: psycopg
Hi,
Thank you for fast response.
Sorry, Daniel, for accidentally sending you answer.
As i understood, to enable debug in psycopg2 i need to recompile it?
Now without debug:

In [29]: cur=conn.cursor('1234')

In [30]: cur.itersize=3

In [31]: cur.execute("select generate_series(1,20)")

In [32]: for i in cur: print i,'end of iteration step'
(1,) end of iteration step
(2,) end of iteration step
(3,) end of iteration step
(4,) end of iteration step
(5,) end of iteration step
(6,) end of iteration step
(7,) end of iteration step
(8,) end of iteration step
(9,) end of iteration step
(10,) end of iteration step
(11,) end of iteration step
(12,) end of iteration step
(13,) end of iteration step
(14,) end of iteration step
(15,) end of iteration step
(16,) end of iteration step
(17,) end of iteration step
(18,) end of iteration step
(19,) end of iteration step
(20,) end of iteration step

I assuming, that chunk of data on every iteration consists of 3 ints:
(1,2,3,) end of iteration step
As mentioned in docs:
The attribute itersize now controls how many records are fetched at
time during the iteration:
(http://initd.org/psycopg/docs/usage.html#server-side-cursors)
Or i misunderstood the docs?

Alex


2012/5/16 Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>:
> 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

psycopg by date

Next:From: Daniele VarrazzoDate: 2012-05-16 12:59:46
Subject: Re: Question aboud #80 - itersize in cursor dic
Previous:From: Daniele VarrazzoDate: 2012-05-16 10:48:06
Subject: Re: Question aboud #80 - itersize in cursor dic

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group