SPI_MODIFYTUPLE(3)
πΈ NAME πΈ
okay so welcome to the SPI_MODIFYTUPLE(3) page from the PostgreSQL 14.24 documentation, bestie. SPI_modifytuple β create a row by replacing selected fields of a given row. That's the whole vibe in one line, and honestly? iconic. π
β¨ 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. The new row is returned in the upper executor context. π«Ά
This function can only be used while connected to SPI. Otherwise, it returns NULL and sets SPI_result to SPI_ERROR_UNCONNECTED. So like, if SPI isn't active, it's not giving new-row energy. π
π 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.) They said it, not me, but we respect the lore.HeapTuple rowβ row to be modified.int ncolsβ number of columns to be changed.int * colnumβ an array of lengthncols, containing the numbers of the columns that are to be changed (column numbers start at1).Datum * valuesβ an array of lengthncols, containing the new values for the specified columns.const char * nullsβ an array of lengthncols, describing which new values are null.- If
nullsisNULLthenSPI_modifytupleassumes that no new values are null. - Otherwise, each entry of the
nullsarray 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 that
nullsis not a text string, just an array: it does not need a'\0'terminator.
- If
π RETURN VALUE π
You get a new row with modifications, allocated in the upper executor context, or NULL on error (see SPI_result for an error indication). Slay when it works, check the error when it doesn't. π
On error, SPI_result is set as follows:
SPI_ERROR_ARGUMENTβ ifrelisNULL, or ifrowisNULL, or ifncolsis less than or equal to0, or ifcolnumisNULL, or ifvaluesisNULL.SPI_ERROR_NOATTRIBUTEβ ifcolnumcontains an invalid column number (less than or equal to0or greater than the number of columns inrow).SPI_ERROR_UNCONNECTEDβ if SPI is not active.
mwah π β this whole page is PostgreSQL 14.24, dated 2026, and it's a SPI_MODIFYTUPLE(3) moment fr fr. πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14-docs 14.24-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms