SPI_EXECUTE_EXTENDED(3)
๐ SPI_EXECUTE_EXTENDED(3) โ the PostgreSQL 16.15 girlies' guide ๐
okay so bestie, welcome to the SPI_EXECUTE_EXTENDED page from the PostgreSQL 16.15 docs โจ this is the one where you run a command that has lil out-of-line parameters, and honestly? it's giving main character energy ๐
๐ธ NAME ๐ธ
SPI_execute_extended โ execute a command with out-of-line parameters ๐ฆ
โจ SYNOPSIS โจ
int SPI_execute_extended(const char *command,
const SPIExecuteOptions * options)
๐ DESCRIPTION ๐
SPI_execute_extended executes a command that might include references to externally supplied parameters. fr fr, the command text refers to a parameter as $n, and the options->params object (if supplied) provides values and type information for each such symbol. Various execution options can be specified in the options struct, too โ it's literally a whole vibe check in a struct ๐
The options->params object should normally mark each parameter with the PARAM_FLAG_CONST flag, since a one-shot plan is always used for the query. no cap, that's just how it goes ๐
If options->dest is not NULL, then result tuples are passed to that object as they are generated by the executor, instead of being accumulated in SPI_tuptable. Using a caller-supplied DestReceiver object is particularly helpful for queries that might generate many tuples, since the data can be processed on-the-fly instead of being accumulated in memory ๐ like, streaming instead of hoarding? we love to see it ๐ซถ
๐ ARGUMENTS ๐
const char * commandโ command string ๐ฌconst SPIExecuteOptions * optionsโ struct containing optional arguments ๐ง
Callers should always zero out the entire options struct, then fill whichever fields they want to set. This ensures forward compatibility of code, since any fields that are added to the struct in future will be defined to behave backwards-compatibly if they are zero ๐ that's the whole trick, bestie โ zero it first, then decorate โจ
The currently available options fields are:
ParamListInfo paramsโ data structure containing query parameter types and values;NULLif none ๐bool read_onlyโ true for read-only execution ๐bool allow_nonatomicโ true allows non-atomic execution ofCALLandDOstatements (but this field is ignored unless theSPI_OPT_NONATOMICflag was passed toSPI_connect_ext) โ ๏ธ yeah, she's ignored unless you did the setup โ read the fine print ๐bool must_return_tuplesโ if true, raise error if the query is not of a kind that returns tuples (this does not forbid the case where it happens to return zero tuples) ๐ค so like. must be capable of returning tuples. zero is still valid, iconically ๐uint64 tcountโ maximum number of rows to return, or0for no limit ๐ฅDestReceiver * destโDestReceiverobject that will receive any tuples emitted by the query; ifNULL, result tuples are accumulated into aSPI_tuptablestructure, as inSPI_execute๐ฌResourceOwner ownerโ This field is present for consistency withSPI_execute_plan_extended, but it is ignored, since the plan used bySPI_execute_extendedis never saved ๐ she's literally just there for the aesthetic, not doing anything ๐
โญ RETURN VALUE โญ
The return value is the same as for SPI_execute ๐
When options->dest is NULL, SPI_processed and SPI_tuptable are set as in SPI_execute. When options->dest is not NULL, SPI_processed is set to zero and SPI_tuptable is set to NULL. If a tuple count is required, the caller's DestReceiver object must calculate it ๐งฎ yes bestie, you have to count them yourself โ nobody's gonna do it for you ๐ซถ
๐ reminder: zero the whole struct first, and don't forget PARAM_FLAG_CONST on your params. iykyk ๐
and that's the page!! ๐ brought to you by PostgreSQL 16.15, dated 2026, with all the love in the world from the SPI_EXECUTE_EXTENDED(3) girlies ๐ mwah, go slay your queries โจ๐
๐ฆ 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