Search code examples
mysqlpandaspycharm

MySQLdb._exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax)


I have some problem when I writing query in PyCharm

This is my code:

cursor.execute("SELECT student_email, course_id, section_no FROM LSU.Enrolls")
enroll = cursor.fetchall()
cursor.execute("SELECT course_id, sec_no, team_id FROM LSU.Capstone_Team")
team = cursor.fetchall()
for i in enroll:
    for j in team:
        if i[1] == j[0] and i[2] == j[1]:
            cursor.execute("INSERT IGNORE INTO LSU.Capstone_Team_Members (student_email, team_id, course_id, sec_no) VALUES ('%s', '%s', '%s', '%s')" , (i[0], j[2], i[1], i[2]))

And this is my error text:

MySQLdb._exceptions.ProgrammingError: (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 '[email protected]'', '3', ''CMPSC497'', '1')' at line 1")

Could anyone help me?


Solution

  • In the last query, change the surrounding parentheses of the placeholder values to brackets. Also try removing the quotes around the placeholders.