SPI_MODIFYTUPLE(3)
π SPI_MODIFYTUPLE(3) β the PostgreSQL glow-up page β¨
okay bestie, welcome to SPI_MODIFYTUPLE(3) from the PostgreSQL 17.11 docs β like, yes it's a C function page, but it's actually iconic once you get it π«Ά
πΈ NAME πΈ
SPI_modifytuple β makes a whole new row by swapping out the fields you pick from a row you already have π
β¨ SYNOPSIS β¨
HeapTuple SPI_modifytuple(Relation rel, HeapTuple row, int ncols,
int * colnum, Datum * values, const char * nulls)
π DESCRIPTION π
So SPI_modifytuple creates a new row by substituting new values into selected columns, and it copies over the original row's columns everywhere else. The way it just... leaves the input row alone? respectful. untouched. not modified. periodt π
The new row comes back to you in the upper executor context.
β οΈ Big caveat, no cap: this function can only be used while connected to SPI. If you're not connected, it returnsNULLand setsSPI_resulttoSPI_ERROR_UNCONNECTED. it's giving "you must be this tall to ride" π’
π ARGUMENTS π
Relation relβ literally only used as the source of the row descriptor for the row. ngl the docs themselves call passing a relation instead of a row descriptor a misfeature π so like. know that going in πHeapTuple rowβ the row you're gonna modify β¨int ncolsβ how many columns you're changing π’int * colnumβ an array of lengthncolsholding the numbers of the columns to be changed. heads up: column numbers start at 1 πDatum * valuesβ an array of lengthncolswith the new values for those specified columns πconst char * nullsβ an array of lengthncolsthat describes which of your 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 that null case, the actual value sitting in the corresponding values entry doesn't matter at all β it's giving decorative π) Also important: nulls is not a text string, it's just an array, so it does not need a '\0' terminator π«
π RETURN VALUE π
A new row with your modifications, allocated in the upper executor context β or NULL on error (peep SPI_result for the error indication π).
On error, SPI_result gets set like this:
SPI_ERROR_ARGUMENTβ ifrelisNULL, or ifrowisNULL, or ifncolsis less than or equal to0, or ifcolnumisNULL, or ifvaluesisNULL. basically if anything's missing, she's not doing it π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 π
and that's the whole page bestie, you ate that π β this was SPI_MODIFYTUPLE(3) from the PostgreSQL 17.11 documentation, dated 2026. go be the main character of your own query planner ππ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17-docs 17.11-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