mysql insert with tuple

Christian mining.facts at gmail.com
Wed Nov 21 12:19:15 EST 2012


Hi ,

my purpose is a generic insert via  tuple , because the number of fields and can differ. But  I'm stucking .

ilist=['hello',None,7,None,None]

#This version works, but all varchar fields are in extra '' enclosed.
con.execute(""" INSERT INTO {} VALUES %r; """.format(table) , (tuple(ilist),))

#This produce (1054, "Unknown column 'None' in 'field list'"),
#but without None values it works.
con.execute(""" INSERT INTO {} VALUES %r; """.format(table) % (tuple(ilist),))


Many thanks,
Christian





More information about the Python-list mailing list