Listo, este es el código:
Código MySQL:
Ver originalDELIMITER $$
RETURN 1; -- Si es macho, devolver 1
RETURN 0; -- Si es hembra, devolver 0
ELSE -- Si el animal no existe en la tabla, INSERT INTO animales
(nombre
, sexo
) VALUES(animal
, "macho"); -- Por defecto será siempre macho RETURN 2; -- Devolvemos 2
Mensaje de error:
Cita: ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
Google:
Debes especificar qué hará la función, si DETERMINISTIC, si va a modificar datos de tablas...
También me dice: ejecuta SET GLOBAL log_bin_trust_function_creators = 1;
Entonces, si en la función pueden haber distintos casos (como ocurre en esta función), que o hacemos SELECT o hacemos un INSERT, y no sabemos previamente si modificaremos o solamente haremos SELECT, ¿qué hago?