Обсуждение: executemany with select

Поиск
Список
Период
Сортировка

executemany with select

От
Damon Fasching
Дата:
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