On 7.4:
This is what we wanted to do:
IF TG_OP = 'INSERT' OR (TG_OP = 'UPDATE' AND NEW.name != OLD.name) THEN
EXECUTE x;
END IF;
However, we had to write it like this:
IF TG_OP = 'INSERT' THEN
EXECUTE x;
ELSIF TG_OP = 'UPDATE' AND NEW.name != OLD.name THEN
EXECUTE x;
END IF;
Because in the first case it would complain that OLD.name wasn't
defined, if the trigger was NOT an update.
OK, but the second case works??!?! Is this a weird peculiarity of the
pl/pgsql lazy evaluation rules? Why doesn't the first one work if the
second one does?
Chris