SPI_RETURNTUPLE(3)

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

πŸ’… SPI_RETURNTUPLE(3) πŸ’…

okay so bestie, this is the PostgreSQL 15.19 Documentation page for SPI_returntuple, and we're about to make returning a tuple as a Datum make sense. no cap. ✨


πŸŽ€ NAME πŸŽ€

SPI_returntuple β€” prepare to return a tuple as a Datum


✨ SYNOPSIS ✨

HeapTupleHeader SPI_returntuple(HeapTuple row, TupleDesc rowdesc)

πŸ’– DESCRIPTION πŸ’–

So SPI_returntuple makes a copy of a row in the upper executor context, and returns it in the form of a row type Datum. The returned pointer only needs to be converted to Datum via PointerGetDatum before returning. literally that's the whole vibe. πŸ¦‹

Important vibe check: this function can only be used while connected to SPI. Otherwise, it returns NULL and sets SPI_result to SPI_ERROR_UNCONNECTED. not me finding out the hard way 😭

Also note: this should be used for functions that are declared to return composite types. It is not used for triggers β€” for returning a modified row in a trigger, use SPI_copytuple instead. periodt. πŸ’…


🌸 ARGUMENTS 🌸

  • HeapTuple row β€” the row to be copied. yes bestie, that row right there.
  • TupleDesc rowdesc β€” descriptor for row (pass the same descriptor each time for most effective caching). lowkey important for that caching slay. πŸŽ€

🫢 RETURN VALUE 🫢

A HeapTupleHeader pointing to the copied row, or NULL on error (see SPI_result for an error indication). if it's NULL, go check SPI_result, iykyk. πŸ’œ


πŸ’œ xoxo, your PostgreSQL 15.19 bestie β€” page dated 2026, signing off with SPI_RETURNTUPLE(3) energy. πŸŽ€

πŸ“¦ where this page comes from