SPI_modifytuple
Синтаксис
HeapTuple SPI_modifytuple(Relation rel, HeapTuple row, int ncols,
int * colnum, Datum * values, const char * nulls)Описание
SPI_modifytuple создаёт новую строку, подставляя новые значения для указанных колонок и копируя исходное содержимое остальных колонок. Исходная строка не изменяется.
Аргументы
- Relation rel
Используется только в качестве дескриптора строки. (Передача отношения вместо собственно дескриптора строки — нехорошая особенность.)
- HeapTuple row
строка, подлежащая изменению
- int ncols
число изменяемых колонок
- 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 — NULL
- SPI_ERROR_NOATTRIBUTE
если colnum содержит недопустимый номер колонки (меньше или равен 0, либо больше числа колонок в строке row)
| Пред. | Начало | След. |
| SPI_returntuple | Уровень выше | SPI_freetuple |
SPI_modifytuple
Synopsis
HeapTuple SPI_modifytuple(Relation rel, HeapTuple row, int ncols,
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
- Relation rel
Used only as the source of the row descriptor for the row. (Passing a relation rather than a row descriptor is a misfeature.)
- HeapTuple row
row to be modified
- int ncols
number of columns to be changed
- int * colnum
an array of length ncols, containing the numbers of the columns that are to be changed (column numbers start at 1)
- Datum * values
an array of length ncols, containing the new values for the specified columns
- const char * nulls
an array of length ncols, describing which new values are null
If nulls is NULL then
SPI_modifytupleassumes that no new values are null. Otherwise, each entry of the nulls array 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 corresponding values entry doesn't matter.) Note that nulls is 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_ARGUMENT
if rel is NULL, or if row is NULL, or if ncols is less than or equal to 0, or if colnum is NULL, or if values is NULL.
- SPI_ERROR_NOATTRIBUTE
if colnum contains an invalid column number (less than or equal to 0 or greater than the number of column in row)