2

I would like to include a user variable in the MySQL `LOAD DATA LOCAL INFILE' file path. Our small team often accesses raw data files from Dropbox, so everyone has to find/replace the user name in the path definitions.

I was expecting the following to work but keep getting syntax errors:

SET @USER := 'user';
SET sql_mode='PIPES_AS_CONCAT';
LOAD DATA LOCAL 
INFILE '/Users/' || @USER || '/Dropbox/Data/data.csv'

Also fails with CONCAT(). Any ideas? Thanks!

Similar questions asked here: Load data Infile @variable into infile error but without accepted answer.

Community
  • 1
  • 1
Stefan
  • 41,759
  • 13
  • 76
  • 81

1 Answers1

0

A citation from MySQL documentation:

The file name must be given as a literal string. On Windows, specify backslashes in path names as forward slashes or doubled backslashes. The character_set_filesystem system variable controls the interpretation of the file name.

That means that it can not be a parameter of a prepared statement, stored procedure, or anything "server-side". The string/path evaluation must be done client side.

Binary Alchemist
  • 1,600
  • 1
  • 13
  • 28