Re: Resdhift's lack of cursors and PQsetSingleRowMode - Mailing list psycopg

From Daniele Varrazzo
Subject Re: Resdhift's lack of cursors and PQsetSingleRowMode
Date
Msg-id CA+mi_8bne7PeDD0dien1L2tjq3WKnTmJrUqCV01yEr+WLhm92Q@mail.gmail.com
Whole thread Raw
In response to Re: Resdhift's lack of cursors and PQsetSingleRowMode  (Marko Kreen <markokr@gmail.com>)
Responses Re: Resdhift's lack of cursors and PQsetSingleRowMode  (Marko Kreen <markokr@gmail.com>)
List psycopg
On Thu, Dec 26, 2013 at 1:37 PM, Marko Kreen <markokr@gmail.com> wrote:

> The single row mode is designed for following high-level API:
>
>     curs = db.single-row-mode-cursor()
>     curs.execute(sql)
>     for row in curs.fetchall():
>         process(row)

Because it's neither easy nor necessary to have a full-fledged cursor
object we could just have a new method on the cursor, returning an
iterable object responsible of all the state during the iteration:
something like:

    for r in cur.execute_iter(query [, args]):    # better name?
        process(row)

Because in the DBAPI querying and retrieving is done with different
set of methods, I would have preferred something like:

    cur.execute(query)
    for row in cur.iter_single():
        process(row)

but usually psycopg calls both PQexec and PQgetResult during execute()
so this interface wouldn't be straightforward to implement.


>> ISTM that in single row mode you can only get a single row per network

> No, libpq will still works with 8KB buffers over network.

Cool, no performance objection then, thank you for the clarification.


-- Daniele


psycopg by date:

Previous
From: Marko Kreen
Date:
Subject: Re: Resdhift's lack of cursors and PQsetSingleRowMode
Next
From: Marko Kreen
Date:
Subject: Re: Resdhift's lack of cursors and PQsetSingleRowMode