I have some triggers. They need to do stuff when a new row is inserted
or when the value of a particular field changes.
So, something like:
IF TG_OP='INSERT' OR NEW.foo != OLD.foo THEN
-- do stuff
END IF;
RETURN NEW;
Is there anything that guarantees that the NEW.foo != OLD.foo won't
be evaluated (and hence fail, as there is no OLD) on an insert?
Cheers,
Steve
Steve Atkins <steve@blighty.com> writes:
> IF TG_OP='INSERT' OR NEW.foo != OLD.foo THEN
> -- do stuff
> Is there anything that guarantees that the NEW.foo != OLD.foo won't
> be evaluated (and hence fail, as there is no OLD) on an insert?
The only way is to split the expression into two IF commands. The real
problem is not with the evaluation per se, but with plpgsql having to
pass down all the variable values used in the expression before
evaluation can start.
regards, tom lane
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера