SPI_modifytuple
SPI_modifytuple — create a row by replacing selected fields of a given row
Synopsis
HeapTuple SPI_modifytuple(Relationrel, HeapTuplerow, intncols, int *colnum, Datum *values, const char *nulls)
Description
SPI_modifytuple creates a new row by substituting new values for selected columns, copying the original row's columns at other positions. The input row is not modified. The new row is returned in the upper executor context.
This function can only be used while connected to SPI. Otherwise, it returns NULL and sets SPI_result to SPI_ERROR_UNCONNECTED.
Arguments
RelationrelUsed only as the source of the row descriptor for the row. (Passing a relation rather than a row descriptor is a misfeature.)
HeapTuplerowrow to be modified
intncolsnumber of columns to be changed
int *colnuman array of length
ncols, containing the numbers of the columns that are to be changed (column numbers start at 1)Datum *valuesan array of length
ncols, containing the new values for the specified columnsconst char *nullsan array of length
ncols, describing which new values are nullIf
nullsisNULLthenSPI_modifytupleassumes that no new values are null. Otherwise, each entry of thenullsarray should be' 'if the corresponding new value is non-null, or'n'if the corresponding new value is null. (In the latter case, the actual value in the correspondingvaluesentry doesn't matter.) Note thatnullsis not a text string, just an array: it does not need a'\0'terminator.
Return Value
new row with modifications, allocated in the upper executor context, or NULL on error (see SPI_result for an error indication)
On error, SPI_result is set as follows:
SPI_ERROR_ARGUMENTif
relisNULL, or ifrowisNULL, or ifncolsis less than or equal to 0, or ifcolnumisNULL, or ifvaluesisNULL.SPI_ERROR_NOATTRIBUTEif
colnumcontains an invalid column number (less than or equal to 0 or greater than the number of columns inrow)SPI_ERROR_UNCONNECTEDif SPI is not active