On Thu, Sep 01, 2005 at 08:23:31PM -0600, Cristian Prieto wrote: > Hello, I've been working just a little with SPI in a few stored > functions, this is a model of my SP: Please post a real example instead of a "model." The code you posted fails to compile, with errors and warnings like the following: spitest.c: In function `myspi': spitest.c:18: `ret' undeclared (first use in this function) spitest.c:18: (Each undeclared identifier is reported only once spitest.c:18: for each function it appears in.) spitest.c:39: warning: passing arg 2 of `SPI_execp' from incompatible pointer type spitest.c:41: warning: implicit declaration of function `SPI_finnish' spitest.c:16: warning: unused variable `res' Since what you posted doesn't compile, it can't be what you're really doing; that means we have to guess at what the real code looks like. It would be easier to help if we could see the real thing so we don't have to guess. > // This is where the SP and the connection dies! > ret = SPI_execp(plan, val, NULL, 1); val is a bytea * but the second argument to SPI_execp() is a Datum * (the compiler warning hints that something's wrong here). Try something like this: Datum values[1]; values[0] = PointerGetDatum(val); ret = SPI_execp(plan, values, NULL, 1); That works for me in simple tests. If anybody sees a problem with it then please make corrections. -- Michael Fuhr ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match