Interface Support Functions

All functions described in this section may be used by connected and unconnected procedures.

SPI_copytuple

SPI_copytuple makes copy of tuple in upper Executor context.

SPI_copytuple(tuple)

Outputs

HeapTuple

Copied tuple

non-NULL if tuple is not NULL and the copy was successful;
NULL only if tuple is NULL.

SPI_modifytuple

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)

Outputs

HeapTuple

New tuple with modifications

non-NULL if tuple is not NULL and the modify was successful
NULL only if tuple is NULL.

SPI_result

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)

SPI_fnumber

SPI_fnumber returns the attribute number for the attribute with name in fname.

int SPI_fnumber(tupdesc, fname)

Outputs

int

Attribute number

Valid one-based index number of attribute
SPI_ERROR_NOATTRIBUTE if the named attribute is not found.

SPI_fname

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.)

Outputs

char *

Attribute name

NULL if fnumber is out of range
SPI_result set to SPI_ERROR_NOATTRIBUTE on error.

SPI_getvalue

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)

SPI_getbinval

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)

SPI_gettype

SPI_gettype returns a copy of the type name for the specified attribute, or NULL on error.

SPI_gettype(tupdesc, fnumber)

SPI_gettypeid

SPI_gettypeid returns the type OID of the specified attribute.

SPI_gettypeid(tupdesc, fnumber)

SPI_getrelname

SPI_getrelname returns the name of the specified relation.

SPI_getrelname(rel)