dictionary variable formatting in Python's Mysqldb -
i'm trying use dictionary variable in mysqldb insert statement in python 2.7 :
cursor.execute("insert dcpowerstats(ts,totalpower,itpower,availablepower,pue) values (%s %s %s %s %s)",(dict_timestamp[key], dict_abfeeds[key], dict_abitload[key], 1400, pue))
and table :
sql_createpowertable = '''create table if not exists dcpowerstats (ts datetime ,totalpower float,itpower float, availablepower float, pue float)''' cursor.execute(sql_createpowertable) .
when try error:
_mysql_exceptions.programmingerror: (1064, "you have error in sql syntax; check manual corresponds mysql server version right syntax use near '483.9 334.4 1400 1.44706937799043)' @ line 1")
you need commas after each %s
in insert statement:
insert dcpowerstats(ts,totalpower,itpower,availablepower,pue) values (%s, %s, %s, %s, %s)
Comments
Post a Comment