MySQLdb module, method executemany with anything other than strings?

olekristianvillabo at olekristianvillabo at
Thu Aug 25 11:26:40 CEST 2005

The method cursor.executemany is there in order to avoid multiple calls
to cursor.execute().

I have tried, with success, to do like every single example (that I
have found on the www) on the subject shows, to use a insert statement
on the form:
statement = INSERT INTO table (colA,colB,colC) values (%s,%s,%s)

and pass in a list containing tuples
list = [('bla','bla','bla'),('bla','bla','bla'),('bla','bla','bla')]

on the form


This works fine for all strings, but I have never been able to insert a
single integer or a float using this method. I get an error message
reporting that float (or an int) is required.

Statement is then of course changed to something like
statement = INSERT INTO table (colA,colB,colC) values (%s,%i,%f)
list = [('bla',1,0.65),('bla',3,3.7),('bla',3,0.9)]

Havee anybody experienced similar problems?
Am I doing something wrong?
Any feedback is greatly appreciated.

Here is som real output from the interpreter:
>>> statement = 'insert into testtable3 (url,probability) values (%s,%f)'
>>> l
[('url1', 0.98999999999999999), ('url2', 0.89000000000000001)]
>>> cursor.executemany(statement,l)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Python24\Lib\site-packages\MySQLdb\", line 181, in
    self.errorhandler(self, TypeError, msg)
  File "C:\Python24\Lib\site-packages\MySQLdb\", line 33,
in de
    raise errorclass, errorvalue
TypeError: float argument required

More information about the Python-list mailing list