I have this table:
CREATE TABLE public.tbtramite
(
idtramite integer NOT NULL DEFAULT nextval('tbtramite_idtramite_seq'::regclass),
dsdescricao character varying(255),
dttramite timestamp without time zone,
stnotificacao character varying(1),
stretornada character varying(1),
sttramitepublico character varying(1),
idencaminhamento integer NOT NULL,
idunidadeenvio integer NOT NULL,
idusuarioemissor integer,
idusuarioreceptor integer,
CONSTRAINT tbtramite_pkey PRIMARY KEY (idtramite),
CONSTRAINT fk_1pybfodhvhni89th78wu28av3 FOREIGN KEY (idunidadeenvio)
REFERENCES public.tbunidade (idunidade) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_7njc4ihx8teld84auv7b83cht FOREIGN KEY (idusuarioemissor)
REFERENCES public.tbusuario (idusuario) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_986qxqfo4nx3e6chji0q7mymg FOREIGN KEY (idusuarioreceptor)
REFERENCES public.tbusuario (idusuario) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_iqha0kxcqwwfweibygg4p91xu FOREIGN KEY (idencaminhamento)
REFERENCES public.tbencaminhamento (idencaminhamento) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE public.tbtramite
OWNER TO postgres;
And I have a trigger that executes every time a data is entered in this table.
But I would like the trigger to be executed only when inserting the new data from column idusuarioreceptor
was NULL
and the field of idunidadeenvio
was !=
(different) from 1
. >
Is it possible to run this check when launching the trigger? Or do a "light" procedure that checks and then calls the heavier procedure?
A trigger:
CREATE TRIGGER acerto_de_caminho_trigger
AFTER INSERT ON tbtramite
FOR EACH ROW
EXECUTE PROCEDURE acerto_de_caminho();