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.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
Tianyun Ling
  • 1,045
  • 1
  • 9
  • 24
  • Related: http://stackoverflow.com/questions/17889028/concatenate-table-name-on-update-statement-using-mysql-user-defined-variable – Patrick Q Jul 29 '14 at 17:39
  • Please read the rest of the error message: it says the exact point of your code where unexpected stuff was found. – Álvaro González Jul 29 '14 at 17:40
  • `SELECT @A := CONCAT(@my_directory + @ my_file)` – John Ruddell Jul 29 '14 at 17:40
  • possible duplicate of [Parameterizing file name in MYSQL LOAD DATA INFILE](http://stackoverflow.com/questions/2833214/parameterizing-file-name-in-mysql-load-data-infile) – Álvaro González Jul 30 '14 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. – Álvaro González Jul 30 '14 at 17:05

1 Answers1

1

I think MySQL does not support it.

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

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

Community
  • 1
  • 1
Barto
  • 337
  • 2
  • 11
  • 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 – John Ruddell Jul 29 '14 at 17:45
  • 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? – Barto Jul 29 '14 at 17:50
  • 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 :) – John Ruddell Jul 29 '14 at 18:00