I’m new to MySQL procedures. I need to emulate some code that I usually do with PLpgSQL, something like this:
DROP FUNCTION IF EXISTS "aprtr_controlo_tabelas_ins_upd" () CASCADE;
CREATE OR REPLACE FUNCTION "aprtr_controlo_tabelas_ins_upd" ()
RETURNS trigger AS
$BODY$
BEGIN
IF (TG_OP = 'INSERT') THEN
NEW.data_ult_actual := current_timestamp;
NEW.id_utiliz_ins := current_user;
RETURN NEW;
ELSEIF (TG_OP = 'UPDATE') THEN
NEW.data_ult_actual := current_timestamp;
NEW.id_utiliz_upd := current_user;
RETURN NEW;
END IF;
RETURN NULL;
END;
$BODY$
LANGUAGE PLpgSQL
CALLED ON NULL INPUT
VOLATILE
EXTERNAL SECURITY DEFINER;
It is possible in MySQL to write procedures that return a trigger? Or better, can I use a procedure code and call it trigger in an operation of INSERT or UPDATE?
Best Regards,
MySQL only supports specific data types as function return types. As per MySQL documentation
triggeris not a data type. Custom objects as data types is not a feature AFAIK. Supported data types are detailed here.Referene: MySQL CREATE FUNCTION Syntax.