Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to execute following similar type 2 sql queries. While one query is executing successfully but other is giving error

db = MySQLdb.Connection(host="192.168.1.90", port=3306, user="some", passwd="some", db="some")
cur = db.cursor()
cur.executemany("""INSERT INTO test (timepacket,model_no,cycle_time,target,plan,count,difference,bekido,linenumber,shift,runningstatus,remarks) VALUE (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""", datater)
db.commit()
cur1 = db.cursor()
cur1.executemany("""INSERT INTO delay (running,change,nomaterial,breakdown,quality,noplan,line,shift) VALUE(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""", datater1)
db.commit()
db.close()

The first query is working ok while second query is giving error

1064, "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 'change,nomaterial,breakdown,quality,noplan,line,shift) VALUE(507,0,0,0,0,0,1,1)' at line 1") Anyone can help me out why it is happening?

share|improve this question

closed as off-topic by Amal Murali, Second Rikudo, Chris, nKn, user272735 May 2 at 20:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Amal Murali, Second Rikudo, Chris, nKn, user272735
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 2 down vote accepted

change is a reserved keyword. If you named a column "change" you will need to wrap it in ticks.

(I'm not a python dev so I am guessing this is correct):

cur1.executemany("""INSERT INTO delay (running,`change`,nomaterial,breakdown,quality,noplan,line,shift) VALUE(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""", datater1)
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.