executemany with select - Mailing list pgsql-novice

From Damon Fasching
Subject executemany with select
Date
Msg-id Pine.SOL.3.96.1020304190531.18973F-100000@design.lbl.gov
Whole thread Raw
List pgsql-novice
Hi,

If executemany(queryString, sequence) is used with a SELECT query, as in
the example below, it seems that the cursor retains only the data from the
last member of sequence.  Can someone verify this? No big deal, just
trying to get my usage correct.

Thanks,
 Damon

## ===================================================================

import psycopg

conn = psycopg.connect('testdb')
curs = conn.cursor()

curs.execute("CREATE TABLE testtb (key int4, data text)")

s = ((0, 'row1'), (1, 'row2'))
curs.executemany("INSERT INTO testtb VALUES (%d, %s)", s)

keys = ((0,), (1,))
curs.executemany("SELECT name FROM testtb WHERE key = %d", keys)

rows = curs.fetchall()
for row in rows: print row, "\n"

## ==================================================================

produces the output
>>> ('row2',)

---------

May the lights in The Land of Plenty
  shine on the Truth some day        L Cohen


pgsql-novice by date:

Previous
From: Clinton Adams
Date:
Subject: Re: Do Stored Procedures exist (Besides FUNCTIONs)
Next
From: "Hargis"
Date:
Subject: Optimizer and Indexes with Joins