Postgresql 中文操作指南
SPI_modifytuple
SPI_modifytuple — 通过替换给定行的选定字段来创建行
SPI_modifytuple — create a row by replacing selected fields of a given row
Synopsis
HeapTuple SPI_modifytuple(Relation rel, HeapTuple row, int ncols,
int * colnum, Datum * values, const char * nulls)
Description
SPI_modifytuple 通过用所选列的新值替换、将原始行的列复制到其他位置来创建新行。输入行未修改。新行在高于执行者的上下文中返回。
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.
此函数只能在连接到 SPI 时使用。否则,返回 NULL,并将 SPI_result 设置为 SPI_ERROR_UNCONNECTED 。
This function can only be used while connected to SPI. Otherwise, it returns NULL and sets SPI_result to SPI_ERROR_UNCONNECTED.
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_modifytuple assumes 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
在高于执行者的上下文中分配的新行(包含修改),或在错误时分配 NULL (有关错误指示,请参见 SPI_result )
new row with modifications, allocated in the upper executor context, or NULL on error (see SPI_result for an error indication)
出现错误时, SPI_result 设置如下:
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 columns in row)
-
-
SPI_ERROR_UNCONNECTED
-
if SPI is not active
-