Skip site navigation (1) Skip section navigation (2)

executemany with select

From: Damon Fasching <fasching(at)design(dot)lbl(dot)gov>
To: pgsql-novice(at)postgresql(dot)org
Subject: executemany with select
Date: 2002-03-05 03:13:38
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

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.


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

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

Next:From: HargisDate: 2002-03-05 05:01:28
Subject: Optimizer and Indexes with Joins
Previous:From: Clinton AdamsDate: 2002-03-05 00:53:54
Subject: Re: Do Stored Procedures exist (Besides FUNCTIONs)

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group