Try this:
CREATE OR REPLACE FUNCTION lst_tot_mytable_LOG() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF (TG_OP = 'UPDATE') THEN
INSERT INTO lst_tot_mytable_log SELECT 'U', now(), OLD.*;
IF OLD.Peticionario != NEW.Peticionario
or OLD.interlocclte != NEW.interlocclte
or OLD.Equipo != NEW.Equipo
or OLD.RespTecnico != NEW.RespTecnico
or OLD.RespOrganiz != NEW.RespOrganiz THEN
UPDATE lst_tot_mytable set fultimamodificacion = now(),
esmodificadoerspectoaanterior = true
WHERE nropeti = OLD.nropeti;
ELSIF OLD.Peticionario = NEW.Peticionario
or OLD.interlocclte = NEW.interlocclte
or OLD.Equipo = NEW.Equipo
or OLD.RespTecnico = NEW.RespTecnico
or OLD.RespOrganiz = NEW.RespOrganiz THEN
UPDATE lst_tot_mytable set NEW.fultimamodificacion = now(),
NEW.esmodificadoerspectoaanterior = fase
WHERE nropeti = OLD.nropeti;
END IF;
RETURN NULL; -- result is ignored since this is an AFTER trigger
END;
$$;
However if I get your purpose I suspect the ELSIF section may need to be
AND's:
ELSIF OLD.Peticionario = NEW.Peticionario
AND OLD.interlocclte = NEW.interlocclte
AND OLD.Equipo = NEW.Equipo
AND OLD.RespTecnico = NEW.RespTecnico
AND OLD.RespOrganiz = NEW.RespOrganiz THEN
On 05/31/2016 03:18 PM, carlos@xxxxxxxx wrote:
CREATE OR REPLACE FUNCTION lst_tot_mytable_LOG() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF (TG_OP = 'UPDATE') THEN
INSERT INTO lst_tot_mytable_log SELECT 'U', now(), OLD.*;
IF OLD.Peticionario != NEW.Peticionario or OLD.interlocclte !=
NEW.interlocclte or OLD.Equipo != NEW.Equipo or OLD.RespTecnico !=
NEW.RespTecnico or OLD.RespOrganiz != NEW.RespOrganiz THEN
UPDATE lst_tot_mytable set fultimamodificacion = now(),
esmodificadoerspectoaanterior = true WHERE nropeti = OLD.nropeti;
ELSIF OLD.Peticionario == NEW.Peticionario or OLD.interlocclte ==
NEW.interlocclte or OLD.Equipo == NEW.Equipo or OLD.RespTecnico ==
NEW.RespTecnico or OLD.RespOrganiz == NEW.RespOrganiz THEN
UPDATE lst_tot_mytable set NEW.fultimamodificacion = now(),
NEW.esmodificadoerspectoaanterior = fase WHERE nropeti = OLD.nropeti;
END IF;
RETURN NULL; -- result is ignored since this is an AFTER trigger
END;
$$;
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general