how to run trigger on table on postgresql except one column
0
votes
2
answers
1685
views
I'm using postgresql 13/14.
lets say I have a table with column A,B,C,D,E
I have created a trigger for the table that would run every insert/update/delete. (but in this problem, I only need it for update actually, the trigger function is just a bit generic)
it has run good for now.
problem is, column E is only for checking, and it's not needed to run the trigger if it's updated.
my trigger function, is now like this:
CREATE FUNCTION public.fnc_check()
RETURNS trigger
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$
BEGIN
if NEW.AOLD.A and NEW.BOLD.B and NEW.COLD.C and NEW.DOLD.D then
-- do something
end if;
RETURN NEW;
END;
$BODY$;
problem is, on my real table, there are like 20-30 columns and it's a hassle to make if for every columns except for column E.
so, is there a way to make sure the trigger only run for column A,B,C,D and not E (without using if for each other columns except E) ?
thx very much
Asked by Fire
(1 rep)
Oct 26, 2022, 10:16 AM
Last activity: Jun 2, 2025, 05:04 AM
Last activity: Jun 2, 2025, 05:04 AM