SPI_MODIFYTUPLE(3)
π SPI_MODIFYTUPLE(3) π
okay bestie, gather round, because we're talking about SPI_modifytuple β yes the manual page, yes it's real, yes it's iconic β¨
πΈ NAME πΈ
SPI_modifytuple β make a whole new row by swapping out some of the fields in a row you already have π
π¦ SYNOPSIS π¦
HeapTuple SPI_modifytuple(Relation rel, HeapTuple row, int ncols,
int * colnum, Datum * values, const char * nulls)
π DESCRIPTION π
so basically? SPI_modifytuple builds you a brand new row by subbing in new values for the columns you picked, and it just copies the original row's columns everywhere else. it's giving "glow up but only for the columns you chose" π
the input row is not modified. like, at all. she stays exactly as she was. no cap.
the new row gets returned in the upper executor context.
and here's the important part, bestie: this function can only be used while you're connected to SPI. if you're not? she returns NULL and sets SPI_result to SPI_ERROR_UNCONNECTED. no connection, no service, periodt π
β¨ ARGUMENTS β¨
Relation relβ literally only used as the source of the row descriptor for the row. that's it. that's her whole job. (and ngl, the original docs say passing a relation instead of a row descriptor is a misfeature β so, yeah, we all know, we're just not making it a thing π)HeapTuple rowβ the row you wanna modify πint ncolsβ how many columns you're changing, count 'emint * colnumβ an array of lengthncolsholding the numbers of the columns you want to change. and heads up: column numbers start at 1, not 0, iykykDatum * valuesβ an array of lengthncolswith the new values for those columns you namedconst char * nullsβ an array of lengthncolsthat says which of the new values are null- if
nullsisNULL, thenSPI_modifytuplejust assumes none of the new values are null. easy, low effort, love that for us π - otherwise, each entry in the
nullsarray should be' 'if that new value is non-null, or'n'if that new value is null. (and in that'n'case, the actual value sitting in the matchingvaluesentry literally does not matter, so don't stress π«Ά) - and pls note:
nullsis not a text string, she's just an array. she does not need a'\0'terminator. do not come for her with string energy, that's not the vibe π
- if
π RETURN VALUE π
you get back the new row with the modifications, allocated in the upper executor context. or, if things went sideways, NULL on error (go check SPI_result for the error indication, she'll tell you what happened π).
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 you handed her nothing, or negative somethings, she's not doing that πSPI_ERROR_NOATTRIBUTEβ ifcolnumcontains an invalid column number (less than or equal to0, or greater than the number of columns inrow). remember: start at 1, stay in range β¨SPI_ERROR_UNCONNECTEDβ if SPI is not active. no SPI, no row, that's the rule π
fr fr bestie, the vibes here are simple: you in SPI? you get a row. you not in SPI? you get NULL and an error code. choose wisely π§
and that's the whole page, we ate, no crumbs left π
this lil masterpiece came to you courtesy of PostgreSQL 18.6, dated 2026, and honestly? iconic of them. k bye πβ¨π
π¦ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 Β· PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 Β· PostgreSQL
- arch rolling: postgresql 18.6-4 Β· PostgreSQL
- fedora 43: postgresql-server-devel 18.6-1.fc43 Β· PostgreSQL
- fedora 43: postgresql-server-devel 18.6-1.fc43 Β· PostgreSQL
- fedora 44: postgresql-server-devel 18.6-1.fc44 Β· PostgreSQL
- fedora 44: postgresql-server-devel 18.6-1.fc44 Β· PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-doc-18 18.6-0ubuntu0.26.04.1 Β· PostgreSQL
- ubuntu stonking: postgresql-doc-18 18.6-3build2 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms