UPDATE `temp` SET `UnixTimestamp` = UNIX_TIMESTAMP(STR_TO_DATE(`Datum`,'%d.%c.%Y %H:%i:%s'))
Wenn ich diesen so in phpmyadmin eingebe, macht er das,wandelt also die Spalte Datum in einen Unix Timestamp.
Wenn ich nun aber mittels:
Code: Alles auswählen
dat = "Datum"
sql = "UPDATE `temp` SET `UnixTimestamp` = UNIX_TIMESTAMP(STR_TO_DATE(`" + dat + "`,'%d.%c.%Y %H:%i:%s'));"
Code: Alles auswählen
dat = "Datum"
sql = """UPDATE `temp` SET `UnixTimestamp` = UNIX_TIMESTAMP(STR_TO_DATE(`" %s "`,'%d.%c.%Y %H:%i:%s'));""" % dat
den Befehl mit Python ausführen will, bekomm ich einen
mysql_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 'U' at line 1")
Weiss jemand, an was das liegt?
Wie gesagt, wenn ich die Zeile mit print sql in der KOnsole ausgeben lasse und direkt in meine MySQL-Konsole kopiere, funktioniert es.