While fooling with the recent contrib problem
http://archives.postgresql.org/pgsql-committers/2008-11/msg00346.php
I noticed another way that tablefunc.c is being cavalier about the
state when it returns control: the crosstab() function returns with
an internal SPI call still active! This is relatively harmless in
the case where it's being called by MakeTableFunctionResult; but you
can expose an error in other cases, for instance running two of 'em
in parallel:
contrib_regression=# SELECT crosstab3( 'select rowid, attribute, value from ct where attribute = ''att2'' or
attribute= ''att3'' order by 1,2'), crosstab3( 'select rowid, attribute, value from ct where attribute = ''att2'' or
attribute= ''att3'' order by 1,2');
ERROR: crosstab: SPI_connect returned -1
The right way to fix this IMHO is to change the function to be called
only once and accumulate its results into a tuplestore. That'll be
marginally more efficient, too.
Think I'll go fix this while I'm watching the football game ...
regards, tom lane