Joel Burton <jburton(at)scw(dot)org> writes:
> If I try to INSERT into this table, I get
> ERROR: record old is unassigned yet
> So, why hasn't the logic short-circuited? Am I missing something?
You lose because those are parameters that plpgsql has to hand to the
SQL expression evaluator. The expression evaluator might have
short-circuited that part of the expression when it ran it, but it never
gets to run it; plpgsql errors out while setting up for the expression
eval.
I think you'll have to split this into multiple IF statements if you
want to make it work like that. Possibly better: use separate trigger
functions for the INSERT and UPDATE cases to begin with.
regards, tom lane