Alex Pilosov <alex@pilosoft.com> writes:
> Something (when the query is evaluated, before cust_name function is
> called) sets the tupdesc->natts=0,
FWIW, I have just looked through all the code that sets natts fields,
and I don't believe that any of it can set a tupdesc's natts field to
zero. Therefore the zeroing must be an accidental stomp of some kind.
Since natts is the first field in a tupdesc, it seems plausible that
this might happen if some bit of code misinterprets a tupdesc pointer
as something else. However, that makes the odds of finding the problem
by staring at code even lower. I really need to get after this with
a debugger...
BTW, are you building with --enable-cassert? If not I strongly recommend
it for chasing this sort of problem.
regards, tom lane