executemany with select

Поиск
Список
Период
Сортировка
От Damon Fasching
Тема executemany with select
Дата
Msg-id Pine.SOL.3.96.1020304190531.18973F-100000@design.lbl.gov
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: Clinton Adams
Дата:
Сообщение: Re: Do Stored Procedures exist (Besides FUNCTIONs)
Следующее
От: "Hargis"
Дата:
Сообщение: Optimizer and Indexes with Joins