-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- TRIGGER BEFORE INSERT
-- Tabla: sga_elementos
-- Version 3.0.0
-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

-- DROP FUNCTION ftib_sga_elementos();
CREATE OR REPLACE FUNCTION ftib_sga_elementos() RETURNS TRIGGER AS $BODY$
  BEGIN
       -- Genera un registro en la tabla de entidades..
       NEW.entidad := f_generar_entidad(NEW.entidad_subtipo);    -- NEW.entidad := f_generar_entidad(xxxx);
       RETURN NEW;
  END;
$BODY$ LANGUAGE plpgsql;


-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Trigger de INSERT sobre sga_elementos
-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- DROP TRIGGER tib_sga_elementos ON sga_elementos RESTRICT;
CREATE TRIGGER tib_sga_elementos 
    BEFORE INSERT ON sga_elementos
    FOR EACH ROW EXECUTE PROCEDURE ftib_sga_elementos();
