Thank you very much Joe.
I have followed the crosstab() implementation and understood the idea of per query memory context. Now, I am using a unique SPI instance (which I perform several sql queries), process the result, transform my result into a tuplestore, close the SPI and done. It works perfectly.
I have a curiosity with regard to the tuplestore: is there a problem with performance if my tuplestore form a big table with million of tuples? Other question is regarding to SPI: is there a problem to use only one instance of SPI (for instance, if multiple users call the same function)?
Thank you again,
Anderson Carniel