How to use server side cursors with psycopg2 : <p>I have a table with 4million rows and I use psycopg2 to execture a:</p>

<pre><code>   SELECT * FROM ..WHERE query
</code></pre>

<p>I haven't heard before of the server side cursor and I am reading its a good practice when you expect lots of results.</p>

<p>I find the documentation a bit limited and I have some basic questions. </p>

<p>First I declare the server-side cursor as:</p>

<pre><code>cur = conn.cursor('cursor-name')
</code></pre>

<p>then I execute the query as:</p>

<pre><code>cur.itersize = 10000
sqlstr = "SELECT clmn1, clmn2 FROM public.table WHERE clmn1 LIKE 'At%'"
cur.execute(sqlstr)
</code></pre>

<p>My question is: What do I do now? How do I get the results?</p>

<p>Do I iterate through the rows as:</p>

<pre><code>row = cur.fetchone()
while row:
   row = cur.fetchone()
</code></pre>

<p>or I use fetchmany() and I do this:</p>

<pre><code>row = cur.fetchmany(10)
</code></pre>

<p>But in the second case how can I "scroll" the results?</p>

<p>Also what is the point of itersize? </p>
