Search code examples
mysqlload-data-infile

Unknown column 'date_added' in 'field list'


I am attempting a LOAD DATA INFILE and getting the above error.

LOAD DATA INFILE '$file'
REPLACE INTO TABLE $custom_parts
FIELDS TERMINATED BY ',' ESCAPED BY '\\\\'
LINES TERMINATED BY '\\r\\n'
IGNORE 1 LINES
 (`partsno`, `mfg`, `cond`, `price`, `is_deleted`, @date_added)
   SET `date_added` = STR_TO_DATE(@date_added, '%c/%e/%Y'),
  `prtky` = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(partsno, ' ', '' ) 
   , '\\\\', '' ) , '/', '' ) , '_', '' ) , '.', '' ) , '-', '' )

The columns of the file are so

Part Number,MFR,Condition,price,is_deleted,date_added

Whenever I run the PHP to load this, I get the error. I am entrigued as why this is occuring. I believe that it is an issue with the user variable not being assigned and I am just looking for verification.


Solution

  • I answered my own question. ---- User variables may be used in most contexts where expressions are permitted. This does not currently include contexts that explicitly require a literal value, such as in the LIMIT clause of a SELECT statement, or the IGNORE N LINES clause of a LOAD DATA statement.