I am trying to insert data into MYSQL database using a python script and when i execute my program i get an error "Not enough arguments for format string" at the following line.
_cursor.execute("INSERT INTO `md_patentinfo` (patentno, filed)
VALUES ('%s',STR_TO_DATE('%s','%M %d,%Y'))" %(patent_number,issue_date))
MORE INFO ON THE ABOVE LINE :
in the above line i am inserting patent number and Issue date into my table and i am using the STR_TO_DATE to convert the date value in %B %d,%Y format to %M,%d,%Y.
Please help me out
hjpotter92
81.1k36 gold badges148 silver badges188 bronze badges
2 Answers 2
You need to escape the %M, %d and %Y as in:
"INSERT INTO md_patentinfo (patentno, filed) VALUES ('%s',STR_TO_DATE('%s','%%M %%d,%%Y'))" % ('123','Apr 14,2012')
answered Apr 19, 2012 at 22:07
John Gaines Jr.
11.6k1 gold badge28 silver badges25 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Eyal Ch
when i use this format in .execute(query) i get: not enough arguments for format string
Your format string has five arguments (each '%something' is an argument). You probably want to escape the %M, %d%Y part:
"INSERT INTO md_patentinfo (patentno, filed) VALUES ('%s',STR_TO_DATE('%s','%%M %%d,%%Y'))" % (patent_number,issue_date)
answered Apr 19, 2012 at 22:12
sinelaw
16.6k4 gold badges55 silver badges83 bronze badges
Comments
lang-py