0

I am trying to use the code seen in this example here:

MySQL load NULL values from CSV data

I am using this code (Which works when I don't use the last three lines)

LOAD DATA LOCAL INFILE 'Myfiles/Products.csv'
INTO TABLE tblProducts
FIELDS TERMINATED BY ','
  ENCLOSED BY '"'
LINES TERMINATED BY '\n'
(product_id, manufacturer, sku, pname, price, @vstock, @vcategory_id, lf_code)
Set 
stock = ifnull(@vstock = ''),
category_id = ifnull(@vcategory_id = '');

However, I keep getting the Error Code 1582: "Incorrect parameter count in the native function call 'ifnull' " Can someone explain what is going wrong?

Community
  • 1
  • 1
Hound
  • 932
  • 2
  • 17
  • 26

1 Answers1

1

You should beusing NULLIF(), not IFNULL(). It takes two arguments: an expression to return in the normal case, and something else to compare with it, and it returns NULL if they're equal. You don't write = between them.

stock = nullif(@vstock, ''),
category_id = nullif(@vcategory_id, '');
Barmar
  • 741,623
  • 53
  • 500
  • 612