pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: pgsql-general@lists.postgresql.org
To: Ian Zimmerman <itz@very.loosely.org>
Subject: Re: Query ID Values
Date: Tue, 15 May 2018 05:53:10 -0700
Message-ID: <dcd91fab-9b28-6c77-ebc5-0dd604da52b1@aklaver.com> (raw)
In-Reply-To: <20180515050412.s6qmx4yahzp25vgh@matica.foolinux.mooo.com>
References: <CAA6wQLLiPJkHBpH6SKi5QEymC3n-FUKMXm03Msf9Oy4Ut6dK2g@mail.gmail.com>
	<5afa3e76.1c69fb81.c680b.185d@mx.google.com>
	<CAA6wQLLSW9YCe9PcLF1AiFMCtsq5dR3FK4kPZPkPgqYbk4YojQ@mail.gmail.com>
	<CAA6wQLJ3cPPSRwW8rVDH5yu_UbKLk-mbuzkLbEYVqS0D8dBJyQ@mail.gmail.com>
	<927dc5f8-b343-c7ff-e131-17c5c3dc6814@aklaver.com>
	<20180515050412.s6qmx4yahzp25vgh@matica.foolinux.mooo.com>

On 05/14/2018 10:04 PM, Ian Zimmerman wrote:
> On 2018-05-14 21:12, Adrian Klaver wrote:
> 
>> Because you are doing fetchall(). That is going to fetch a list of row
>> tuples.  Either iterate over that list or iterate over the cursor:
>>
>> for row in cur_p:
>> 	print(row)
>>
>> For more info see:
>> http://initd.org/psycopg/docs/cursor.html
> 
> Where does that webpage say that I can use the cursor itself for
> iteration?  I can't find it there.  (OTOH it is clearly documented for
> the sqlite3 library).

Results retrieval methods
"
Note

cursor objects are iterable, so, instead of calling explicitly 
fetchone() in a loop, the object itself can be used:

 >>> cur.execute("SELECT * FROM test;")
 >>> for record in cur:
...     print record

"

> 
> Until now, with psycopg2 I have done it like this:
> 
> cur.execute(stmt)
> results = iter(cur.fetchone, None)
> for r in results:
>      ...
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (11+ messages)

Message-ID: <dcd91fab-9b28-6c77-ebc5-0dd604da52b1@aklaver.com>
Permalink:  ../dcd91fab-9b28-6c77-ebc5-0dd604da52b1@aklaver.com/
Also on:    postgresql.org/message-id/dcd91fab-9b28-6c77-ebc5-0dd604da52b1@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, itz@very.loosely.org
  Subject: Re: Query ID Values
  In-Reply-To: <dcd91fab-9b28-6c77-ebc5-0dd604da52b1@aklaver.com>
  References: <CAA6wQLLiPJkHBpH6SKi5QEymC3n-FUKMXm03Msf9Oy4Ut6dK2g@mail.gmail.com> <5afa3e76.1c69fb81.c680b.185d@mx.google.com> <CAA6wQLLSW9YCe9PcLF1AiFMCtsq5dR3FK4kPZPkPgqYbk4YojQ@mail.gmail.com> <CAA6wQLJ3cPPSRwW8rVDH5yu_UbKLk-mbuzkLbEYVqS0D8dBJyQ@mail.gmail.com> <927dc5f8-b343-c7ff-e131-17c5c3dc6814@aklaver.com> <20180515050412.s6qmx4yahzp25vgh@matica.foolinux.mooo.com> <dcd91fab-9b28-6c77-ebc5-0dd604da52b1@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox