SPI_RETURNTUPLE(3)

πŸ“¦ version 18.6, in opensuse-leap 16.0

πŸ’– SPI_RETURNTUPLE(3) πŸ’–

okay bestie, so this is a page from the PostgreSQL 18.6 Documentation, and today's main character is SPI_returntuple β€” the girl who preps your tuple so it can go out into the world as a Datum. slay. let's get into it. πŸŽ€


✨ NAME ✨

SPI_returntuple β€” get ready to return a tuple as a Datum πŸ’…


🌸 SYNOPSIS 🌸

HeapTupleHeader SPI_returntuple(HeapTuple row, TupleDesc rowdesc)

πŸ¦‹ DESCRIPTION πŸ¦‹

so basically, SPI_returntuple makes a copy of a row over in the upper executor context, and hands it back to you in the form of a row type Datum. the returned pointer? you literally only need to convert it to Datum via PointerGetDatum before returning it. that's it. that's the whole vibe. ✨

🚨 important: this function can only be used while you're connected to SPI. if you're not connected, it returns NULL and sets SPI_result to SPI_ERROR_UNCONNECTED. so, like, vibe check first, okay? πŸ’€

also, heads up: this one is meant for functions that are declared to return composite types. it is not used for triggers β€” if you're returning a modified row in a trigger, use SPI_copytuple instead. different girl, different job, no cap. πŸ‘‘


πŸŽ€ ARGUMENTS πŸŽ€

  • HeapTuple row β€” the row you want copied. just, like, hand her the row. 🫢
  • TupleDesc rowdesc β€” the descriptor for the row. and fr fr, pass the same descriptor every time if you want the most effective caching. consistency is iconic. ⭐

πŸ’œ RETURN VALUE πŸ’œ

a HeapTupleHeader pointing to the copied row β€” or NULL if something went wrong (peep SPI_result for the error indication, she'll tell you what happened). 😭


🌈 SEE ALSO 🌈

okay so the original page didn't list any SEE ALSO references β€” nothing else to link, bestie, that's the whole list. πŸ’–


and that's the page!! this one came from the PostgreSQL 18.6 docs, dated 2026, filed under SPI_RETURNTUPLE(3). go forth and return your tuples, queen. πŸ‘‘βœ¨πŸ¦‹

πŸ“¦ where this page comes from