Hound Hound - 3 months ago 11
MySQL Question

MySQL Load Null Values from CSV data Error Code 1582

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?

Answer

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, '');
Comments