MySQL Forums
Forum List  »  Connector/Python

datetime insert error
Posted by: Yaroslav Didan
Date: September 12, 2018 03:11AM

can you please explain why that code doesn't work
Code (Python):
date = row['actionTime'] #date
my_time = date.strftime('%Y-%m-%d %H:%M:%S')
t_dict[ts] = my_time
placeholders = ', '.join(['%s'] * len(t_dict))
columns = ', '.join(t_dict.keys())
sql = "INSERT INTO {0} ( {1} ) VALUES ( {2} );".format(table, columns, placeholders)
sql_insert = sql %(tuple(t_dict.values()))
cursor = mydb.cursor()
cursor.execute(sql_insert,)
cursor.close()
mydb.close()
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 '12:23:34 )' at line 1
Insert value:
INSERT INTO visits ( personId, visitDt ) VALUES ( 12345, 2010-01-01 12:23:34 );
<class 'str'> - class of 2010-01-01 12:23:34. class 'date' give a same error

Options: ReplyQuote


Subject
Written By
Posted
datetime insert error
September 12, 2018 03:11AM
September 13, 2018 08:44AM
September 13, 2018 09:37AM
September 17, 2018 03:16AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.