Quantcast
Channel: MySQL Forums - Connector/Python
Viewing all articles
Browse latest Browse all 384

Question with python connector 1064 (42000): You have an error in your SQL syntax; (no replies)

$
0
0
I have a small python program to generate following sql

update AggGMDB set GMDBDIFF1 = ifnull(GMDB200603,0)- ifnull(GMDB200512,0)

but it gives the following error

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''GMDBDIFF1' = ifnull('GMDB200603',0)- ifnull('GMDB200512',0)' at line 1

What am I doing wrong

here is a fragment of the python program

count=0
for column1,column2 in columns:
count +=1
print count
NewColumn = "GMDBDIFF" + str(count)
query = "alter table AggGMDB add "+ NewColumn + " decimal(30,2)"
cursor.execute(query)
query ="update AggGMDB set %s = ifnull(%s,0)- ifnull(%s,0)"
print query
print "Computing the difference between %s and %s" %(column1,column2)
print query %(NewColumn,column1,column2)
cursor.execute(query,(NewColumn,column1,column2))
cnx.commit()
cursor.close()
cnx.close()

Viewing all articles
Browse latest Browse all 384

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>