Index: doc/src/sgml/spi.sgml =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/doc/src/sgml/spi.sgml,v retrieving revision 1.65 diff -c -p -r1.65 spi.sgml *** doc/src/sgml/spi.sgml 5 Aug 2009 19:31:50 -0000 1.65 --- doc/src/sgml/spi.sgml 9 Oct 2009 20:16:58 -0000 *************** char * SPI_getnspname(Relation palloc, repalloc, or SPI utility functions (except for SPI_copytuple, + SPI_copydatum, SPI_returntuple, SPI_modifytuple, and SPI_palloc) are made in this context. When a *************** HeapTuple SPI_copytuple(HeapTuple + + + SPI_copydatum + 3 + + + + SPI_copydatum + make a copy of a datum in the upper executor context + + + SPI_copydatum + + + + Datum SPI_copydatum(Datum value, bool typByVal, int typLen) + + + + + Description + + + SPI_copydatum makes a copy of a datum in the + upper executor context. + + + + + Arguments + + + + Datum value + + + datum to be copied + + + + + + bool typByVal + + + whether the type of the datum is passed by value + + + + + + int typLen + + + length of the type + + + + + + + + + Return Value + + + the copied datum; NULL only if + value is NULL + + + + + + SPI_returntuple Index: src/backend/executor/spi.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/executor/spi.c,v retrieving revision 1.209 diff -c -p -r1.209 spi.c *** src/backend/executor/spi.c 2 Oct 2009 17:57:30 -0000 1.209 --- src/backend/executor/spi.c 9 Oct 2009 20:35:03 -0000 *************** SPI_copytuple(HeapTuple tuple) *** 615,620 **** --- 615,635 ---- return ctuple; } + Datum + SPI_copydatum(Datum value, bool typByVal, int typLen) + { + Size len; + void *tmp; + Datum retval; + + len = datumGetSize(value, typByVal, typLen); + tmp = SPI_palloc(len); + memcpy(tmp, DatumGetPointer(value), len); + retval = PointerGetDatum(tmp); + + return retval; + } + HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc) { Index: src/include/executor/spi.h =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/include/executor/spi.h,v retrieving revision 1.72 diff -c -p -r1.72 spi.h *** src/include/executor/spi.h 11 Jun 2009 14:49:11 -0000 1.72 --- src/include/executor/spi.h 9 Oct 2009 20:00:19 -0000 *************** extern bool SPI_plan_is_valid(SPIPlanPtr *** 98,103 **** --- 98,104 ---- extern const char *SPI_result_code_string(int code); extern HeapTuple SPI_copytuple(HeapTuple tuple); + extern Datum SPI_copydatum(Datum value, bool typByVal, int typLen); extern HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc); extern HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum, Datum *Values, const char *Nulls); Index: src/pl/plpgsql/src/pl_exec.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/pl/plpgsql/src/pl_exec.c,v retrieving revision 1.248 diff -c -p -r1.248 pl_exec.c *** src/pl/plpgsql/src/pl_exec.c 6 Aug 2009 20:44:31 -0000 1.248 --- src/pl/plpgsql/src/pl_exec.c 9 Oct 2009 20:36:01 -0000 *************** plpgsql_exec_function(PLpgSQL_function * *** 438,452 **** * into upper executor memory context. */ if (!fcinfo->isnull && !func->fn_retbyval) ! { ! Size len; ! void *tmp; ! ! len = datumGetSize(estate.retval, false, func->fn_rettyplen); ! tmp = SPI_palloc(len); ! memcpy(tmp, DatumGetPointer(estate.retval), len); ! estate.retval = PointerGetDatum(tmp); ! } } } --- 438,445 ---- * into upper executor memory context. */ if (!fcinfo->isnull && !func->fn_retbyval) ! estate.retval = SPI_copydatum(estate.retval, false, ! func->fn_rettyplen); } }