Wednesday, January 22, 2020

ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled


When you create a stored function, you must declare either that it is deterministic or that it does not modify data. Otherwise, it may be unsafe for data recovery or replication.

For example, the following function is not safe

CREATE FUNCTION generatenumber(fid INT(10))
RETURNS INT
BEGIN
 UPDATE xnumber
   SET count = (@cur_value := count+ 1)
   WHERE id=fid;
   return @cur_value;
 
END;

When you attempt to execute a stored function, if binlog_format=STATEMENT is set, the DETERMINISTIC keyword must be specified in the function definition. If this is not the case, an error is generated and the function does not run, unless log_bin_trust_function_creators=1 is specified to override this check

To relax the preceding conditions on function creation (that you must have the SUPER privilege and that a function must be declared deterministic or to not modify data), set the global log_bin_trust_function_creators system variable to 1. By default, this variable has a value of 0, but you can change it like this:

SET GLOBAL log_bin_trust_function_creators = 1;


No comments:

Post a Comment