This project is archived and is in readonly mode.
Executemany fails on non-insert VALUES statements
Reported by Andrew | October 11th, 2012 @ 02:26 AM
When executemany is called with an SQL string using VALUES keyword outside of an insert statement, psycopg2.4.5 seems to only send one row of values to the server. See example below.
----------query----------
query = """SELECT * FROM (VALUES (%s,%s,%s,%s)) AS table("people","Mitt_Romney",cares,about);"""
cursor.executemany(query,all_americans)
people = cursor.fetchall()
for person in people:
print(person)
----------results----------
('The','Top','One','Percent')
(None, None, None, None)
(None, None, None, None)
(None, None, None, None)
(None, None, None, None)
(None, None, None, None)
(None, None, None, None)
(None, None, None, None)
(None, None, None, None)
(None, None, None, None)
(None, None, None, None)
(None, None, None, None)
(None, None, None, None)
...
Comments and changes to this ticket
-
Daniele Varrazzo October 11th, 2012 @ 08:30 AM
- Tag set to executemany, rel-2.4.5
It is surprising that it returns a list of values. executemany shouldn't be called with statements returning rows, only with data manipulation commands: as per DBAPI specs all the results should be discarded.
Looks we build a list as long as the # of records passed, which is bad as they may be a lot. The tuple in the first item is the result of the last statement.
In [11]: cur.executemany("select %s, %s", [(i,i) for i in range(3)]) In [12]: cur.fetchall() Out[12]: [(2, 2), (None, None), (None, None)]
We may clean this up a little bit, but the result should be that fetch returns no record after executemany, not that you'll be able to see each query's result.
-
Daniele Varrazzo October 11th, 2012 @ 09:37 PM
- State changed from new to resolved
Fixed in my devel: after executemany() there is no result to fetch on the cursor (we discard the result from the db and save the time to process it into python objects).
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="https://github.com/psycopg/psycopg2/issues">the new tracker</a>.
<br/>
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.