Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

itersize not honored when using named cursor with RealDictCursor

#80

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"

Reported by Jean-Baptiste Quenot · December 2nd, 2011 @ 03:13 PM

State: resolved
Milestone: none
Assigned to: nobody

Activity

  1. Daniele Varrazzo
    Daniele Varrazzo
    • State changed from new to resolved

    Fixed in my devel branch, thank you for the report.

    December 11th, 2011 @ 09:52 PM