Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Executemany fails on non-insert VALUES statements

#133

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)
...

Reported by Andrew · October 11th, 2012 @ 02:26 AM

State: resolved
Milestone: none
Assigned to: nobody

Activity

  1. Daniele Varrazzo
    Daniele Varrazzo
    • 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.

    October 11th, 2012 @ 08:30 AM

  2. Daniele Varrazzo
    Daniele Varrazzo
    • 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).

    October 11th, 2012 @ 09:37 PM