SPI_modifytuple
SPI_modifytuple — создать строку, заменяя отдельные поля в данной
Синтаксис
HeapTuple SPI_modifytuple(Relationrel, HeapTuplerow, intncols, int *colnum, Datum *values, const char *nulls)
Описание
SPI_modifytuple создаёт новую строку, подставляя новые значения для указанных столбцов и копируя исходное содержимое остальных столбцов. Исходная строка не изменяется.
Аргументы
RelationrelИспользуется только в качестве дескриптора строки. (Передача отношения вместо собственно дескриптора строки — нехорошая особенность.)
HeapTuplerowстрока, подлежащая изменению
intncolsчисло изменяемых столбцов
int *colnumмассив длины
ncols, содержащий номера изменяемых столбцов (начиная с 1)Datum *valuesмассив длины
ncols, содержащий новые значения указанных столбцовconst char *nullsмассив длины
ncols, описывающий, в каких столбцах передаётся NULLЕсли в
nullsпередаётсяNULL,SPI_modifytupleсчитает, что ни один из параметров не равен NULL. В противном случае элемент массиваnullsдолжен содержать' ', если значение соответствующего параметра не NULL, либо'n', если это значение — NULL. (В последнем случае значение, переданное в соответствующем элементеvalues, не учитывается.) Заметьте, чтоnulls— это не текстовая строка, а просто массив: ноль'\0'в конце не нужен.
Возвращаемое значение
новая строка с изменениями, размещённая в верхнем контексте исполнителя; NULL, только если row — NULL
В случае ошибки в SPI_result устанавливается:
SPI_ERROR_ARGUMENTесли
rel—NULL, либоrow—NULL, либоncolsменьше или равно 0, либоcolnum—NULL, либоvalues—NULLSPI_ERROR_NOATTRIBUTEесли
colnumсодержит недопустимый номер столбца (меньше или равен 0, либо больше числа столбцов в строкеrow)
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.
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; NULL only if row is NULL
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 column inrow)