I am running a mysql insert query from my python script and I am running into the following error -
jobsummaryfile = '/home/abcd/projects/starling/daily_job_summary/'+ starling_date +'.tsv'
conn = connect_db()
cursor = conn.cursor()
cursor.execute("LOAD DATA LOCAL INFILE " + jobsummaryfile + " INTO TABLE daily_job_summary FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' (@col1,@col2,@col3,@col4) set (jobname=@col1,queue=@col2,maphours=@col3,reducehours=@col4)")
conn.close()
The error i am getting is -
_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 '/home/abcd/projects/starling/daily_job_summary/2014_02_17.tsv I' at line 1")
It is picking up the I at the end and that is causing it to fail. How do i get rid of this?
Santiago Cepas
4,1322 gold badges28 silver badges31 bronze badges
asked Jun 9, 2014 at 20:52
xyzzz
1,5835 gold badges19 silver badges29 bronze badges
1 Answer 1
The error message shows you, that the parsing not ending with the blank (showing you the "I" from "INTO" next).
You have to (single-)quote your filename, so compose the SQL string with double quotes to embed the ' around filename
obsummaryfile = "'/home/abcd/projects/starling/daily_job_summary/" + starling_date + ".tsv'"
Does this help?
answered Jun 9, 2014 at 21:11
ngulam
1,1051 gold badge7 silver badges11 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
xyzzz
i fixed this issue on my side...I need help with one more thing...I want to modify the above query to insert few more variables from the script into the same table.
default