Consider the following program with the default implementation
of RealDictCursor:
import psycopg2.extras
conn = psycopg2.connect('dbname=test', connection_factory=psycopg2.extras.RealDictConnection)
curs = conn.cursor('unique_name')
curs.itersize = 2000
curs.execute("select * from foo limit 25")
curs.fetchone()
The output with PSYCOPG_DEBUG=1 contains the
following lines:
[0x7f603d53c700] FETCH FORWARD 1 FROM "unique_name"
I have to override the Cursor class like this to
fetch the proper number of rows:
class Cursor(psycopg2.extras.RealDictCursor):
def next(self):
return psycopg2.extras._cursor.next(self)
class Connection(psycopg2.extras._connection):
"""A connection that uses `Cursor` automatically."""
def cursor(self, name=None):
if name is None:
return psycopg2.extras._connection.cursor(self, cursor_factory=Cursor)
else:
return psycopg2.extras._connection.cursor(self, name, cursor_factory=Cursor)
conn = psycopg2.connect('dbname=test', connection_factory=Connection)
...
The debug output is OK:
[0x7f86ba488700] FETCH FORWARD 2000 FROM "unique_name"