0
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 Rigger who executes every time a piece of data is entered in this table.
However, I would like Trigger to be executed only when inserting the new column data idusuarioreceptor
were NULL
and the field of idunidadeenvio
were !=
(different) from 1
.
Is it possible to perform this check when launching Trigger? Or make a "light" process that checks and is then call the heavier process?
To Trigger:
CREATE TRIGGER acerto_de_caminho_trigger
AFTER INSERT ON tbtramite
FOR EACH ROW
EXECUTE PROCEDURE acerto_de_caminho();
put the function and Trigger code
– Rovann Linhalis
I do not see the need to put the codes because my doubt is not in the function and functioning of it, but if one could make another and this call it. Or a condition check for Rigger’s own drive.
– Mateus
But in any case Trigger is there, the function I am still developing, but does not enter the scope of the question
– Mateus
IF (NEW.value <> 1 or new.value null)
I did one like this once:CREATE OR REPLACE FUNCTION public.atualiza_impressora()
RETURNS trigger
AS
$$
begin

IF (NEW.descricao <> OLD.descricao or new.codigoempresa <> old.codigoempresa)
THEN
UPDATE impressoras
SET codigoempresa = new.codigoempresa, setorinstalacao = new.descricao
where codigo = new.codigoimpressora; 

END IF;
return null;
end
$$ LANGUAGE plpgsql
I hope it helps you– R.Santos
At Function, that’s not for you?
– R.Santos
@R.Santos serve, serve. But every function call is highly costly for the bank, in which case at each insertion it will call a function and only inside it will check
– Mateus
@R.Santos what I would like to do is to perform this separate function check, only loading the function if the conditions were set
– Mateus
Doesn’t that help you? https://answall.com/questions/220238/realizar-condi%C3%A7%C3%A3o-na-Trigger
– R.Santos
@R.Santos and as help, tomorrow I will test, but I believe it will solve my problem
– Mateus
@R.Santos despite this ai is in Mysql, twisting pro postgres behave alike
– Mateus
Hopefully, you won’t forget about Feedback alone
– R.Santos