Shridhar Daithankar <shridhar_daithankar@persistent.co.in> writes:
> If the trigger function is precompiled, the error would not be reproducible
> and it will work correctly, right?
Only because the trigger in the example doesn't issue any queries of its
own. If it did, it would cause CommandCounterIncrement(s) anyway.
> Can we precompile such RI triggers on postmaster startup? Could that be a
> workaround?
I've thought for some time that it's a bad idea that there is an extra
CCI done when compiling a plpgsql function, because it creates
inconsistencies of behavior. But getting rid of it does not fix the
fundamental issues here at all, it merely means that this particular
drastically-oversimplified example wouldn't happen to fail.
(IIRC, the extra CCI is actually in spi.c, not in plpgsql, so removing
it could potentially break other code; thus I've hesitated to do it.)
regards, tom lane