I am trying to learn how to make a function in MySQL. I get the following error:
You do not have the SUPER privilege and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)
The MySQL code is from here.
I made a db and gave myself all privileges:
CREATE DATABASE IF NOT EXISTS babydb
GRANT ALL PRIVILEGES ON babydb.* TO ‘peter’@‘localhost’;
Now I have a mini table agro_products in babydb The function is this:
DELIMITER //
CREATE FUNCTION product_category(p DECIMAL)
RETURNS VARCHAR(20) DETERMINISTIC
BEGIN
DECLARE product_type VARCHAR(20);
IF p > 30 then set product_type = 'high range';
ELSEIF p > 20 then set product_type = 'mid range';
ELSE set product_type = 'low range';
END IF;
RETURN product_type;
END//
DELIMITER
UPDATE agro_products SET prod_type = product_category(product_price_Kg);
What can I do about the above error?