SPI_MODIFYTUPLE(3)
π
SPI_MODIFYTUPLE(3) β the SPI_modifytuple glow-up page β¨
okay so bestie, welcome to the SPI_MODIFYTUPLE page from the PostgreSQL 16.15 docs β we're doing a little wardrobe change on a row and honestly it's giving main character energy π
β¨ NAME β¨
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 π
okay so here's the vibe: SPI_modifytuple creates a new row by substituting new values for selected columns, and it copies the original row's columns at all the other positions. The way it just... does the work for you π«Ά
important!! the input row is not modified. she's untouched, she's iconic, we don't touch her π
The new row gets returned in the upper executor context β that's where she lives now β¨
Also, big caveat: this function can only be used while connected to SPI. If you're not connected, it returns NULL and sets SPI_result to SPI_ERROR_UNCONNECTED. it's giving "no connection no service" π
π ARGUMENTS π
Relation relβ used only as the source of the row descriptor for the row. lowkey ngl, passing a relation rather than a row descriptor is a misfeature (the docs literally said it, not me π).HeapTuple rowβ row to be modified. the before pic π₯°int ncolsβ number of columns to be changed. how many glow-ups we doing.int * colnumβ an array of lengthncols, containing the numbers of the columns that are to be changed. plot twist: column numbers start at 1 β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. ok this one needs a lil explanation:- 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 that null case, the actual value in the correspondingvaluesentry doesn't matter β she's not even looking π) - and note:
nullsis not a text string, just an array. it does not need a'\0'terminator. no cap π§
- if
π RETURN VALUE π
new row with modifications, allocated in the upper executor context π β or NULL on error (check SPI_result for the error indication, she'll tell you what went wrong π).
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. basically somebody passed you nothing, bestie πSPI_ERROR_NOATTRIBUTEβ ifcolnumcontains an invalid column number (less than or equal to0, or greater than the number of columns inrow). remember, columns start at 1 π₯SPI_ERROR_UNCONNECTEDβ if SPI is not active. no SPI, no slay π
and that's the whole page, periodt π β¨
this lil masterpiece comes to you courtesy of the PostgreSQL 16.15 docs, dated 2026 β see you in the next manpage, bestie π«Άππ¦πβ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16-docs 16.15-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