All functions described in this section may be used by connected and unconnected procedures.
SPI_copytuple makes copy of tuple in upper Executor context.
SPI_copytuple(tuple) |
Input tuple to be copied.
Copied tuple
non-NULL if tuple is not NULL and the copy was successful; |
NULL only if tuple is NULL. |
SPI_modifytuple creates a new tuple by substituting new values for selected attributes, copying the original tuple's attributes at other positions. The input tuple is not modified.
SPI_modifytuple(rel, tuple, nattrs, attnum, Values, Nulls) |
Used only as a source of tuple descriptor for tuple. (Passing a relation rather than a tuple descriptor is a misfeature.)
Input tuple to be modified
Number of attribute numbers in attnum
Array of numbers of the attributes that are to be changed
New values for the attributes specified
Which attributes are NULL, if any
New tuple with modifications
non-NULL if tuple is not NULL and the modify was successful |
NULL only if tuple is NULL. |
SPI_ERROR_ARGUMENT if rel is NULL or tuple is NULL or natts ≤ 0 or attnum is NULL or Values is NULL. |
SPI_ERROR_NOATTRIBUTE if there is an invalid attribute number in attnum (attnum ≤ 0 or > number of attributes in tuple) |
If successful, a pointer to the new tuple is returned. The new tuple is allocated in upper Executor context.
SPI_fnumber returns the attribute number for the attribute with name in fname.
int SPI_fnumber(tupdesc, fname) |
Input tuple description
Field name
Attribute number
Valid one-based index number of attribute |
SPI_ERROR_NOATTRIBUTE if the named attribute is not found. |
Attribute numbers are 1-based. If the given fname refers to a system attribute (for example, oid), the appropriate negative attribute number will be returned. The caller should be careful to test for exact equality to SPI_ERROR_NOATTRIBUTE to detect errors; a test for a result less than or equal to zero is not correct unless system attributes should be rejected.
SPI_fname returns the attribute name for the specified attribute.
SPI_fname(tupdesc, fnumber) |
Returns a newly-allocated copy of the attribute number. (Use pfree() to release the copy when done with it.)
Input tuple description.
Attribute number
Attribute name
NULL if fnumber is out of range |
SPI_result set to SPI_ERROR_NOATTRIBUTE on error. |
Attribute numbers are 1-based.
SPI_getvalue returns an external (string) representation of the value of the specified attribute. The result is returned as a palloc'd string.
SPI_getvalue(tuple, tupdesc, fnumber) |
Input tuple to be examined
Input tuple description
Attribute number
Attribute value or NULL if attribute is NULL, fnumber is out of range (because SPI_result is set to SPI_ERROR_NOATTRIBUTE), or if no output function is available (because SPI_result set to SPI_ERROR_NOOUTFUNC).
SPI_getvalue allocates storage for the returned string. Use pfree() to release the copy when you are done with it.
Attribute numbers are 1-based.
SPI_getbinval returns the specified attribute's value in internal form (as a datum). SPI_getbinval does not allocate a new space for the Datum. In the case of a passer-by-reference datatype, the Datum will be a pointer into the given tuple.
SPI_getbinval(tuple, tupdesc, fnumber, isnull) |
Input tuple to be examined
Input tuple description
Attribute number
Attribute binary value
flag for NULL value in attribute
SPI_ERROR_NOATTRIBUTE |
Attribute numbers are 1-based.
SPI_gettype returns a copy of the type name for the specified attribute, or NULL on error.
SPI_gettype(tupdesc, fnumber) |
Input tuple description
Attribute number
The type name for the specified attribute number
SPI_ERROR_NOATTRIBUTE |
Attribute numbers are 1-based.
Does not allocate new space for the binary value.
SPI_gettypeid returns the type OID of the specified attribute.
SPI_gettypeid(tupdesc, fnumber) |
Input tuple description
Attribute number
The type OID for the specified attribute number
SPI_ERROR_NOATTRIBUTE |
Attribute numbers are 1-based.
SPI_getrelname returns the name of the specified relation.
SPI_getrelname(rel) |
Input relation
The name of the specified relation
SPI_getrelname allocates storage for the returned name. Use pfree() to release the copy when you are done with it.