0

I got the error saying:

ERROR 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 '@my_directory + @my_file INTO TABLE mytable FIELDS TERMINATED BY ',' E' at line 1

for the following code:

    Set @my_directory = 'my directory';
    Set @my_file = 'my file.csv';

    LOAD DATA INFILE @my_directory + @my_file 
    INTO TABLE mytable 
    FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    LINES TERMINATED BY '\n' IGNORE 1 LINES; 

I want to have a seperate directory and file variable, concat them, get the full filename and load a file.

I also tried concat(@my_directory, @my_file1) but still got the same error.

I am using MySQL 5.6 with MySQL Workbench.

5
  • Related: stackoverflow.com/questions/17889028/… Commented Jul 29, 2014 at 17:39
  • Please read the rest of the error message: it says the exact point of your code where unexpected stuff was found. Commented Jul 29, 2014 at 17:40
  • SELECT @A := CONCAT(@my_directory + @ my_file) Commented Jul 29, 2014 at 17:40
  • possible duplicate of Parameterizing file name in MYSQL LOAD DATA INFILE Commented Jul 30, 2014 at 16:59
  • I've ran your code in my local server and added the full error message into the question. As you can see, it points out the exact bit of the query that's invalid. Error messages are intended as a help for the programmer so it never helps to just dismiss them. Commented Jul 30, 2014 at 17:05

1 Answer 1

1

I think MySQL does not support it.

https://stackoverflow.com/a/14905351/3662004

http://bugs.mysql.com/bug.php?id=39115

Sign up to request clarification or add additional context in comments.

3 Comments

probably should not write this as an answer as it is identical to another answer. rather just point it out in a comment and we can mark as duplicate
Sorry if I do not use the system properly. I do not have 50 reputation so I can not comment. What should I have done?
my bad. didn't know you weren't able to comment. generally posting someone else's answer is a huge nono... but i guess its cool. i'll +1 so you are over 50 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.