SPI_EXECUTE_EXTENDED(3)

๐Ÿ“ฆ version 16.15, in opensuse-leap 16.0

๐Ÿ’… 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; NULL if none ๐Ÿ“
  • bool read_only โ€” true for read-only execution ๐Ÿ”’
  • bool allow_nonatomic โ€” true allows non-atomic execution of CALL and DO statements (but this field is ignored unless the SPI_OPT_NONATOMIC flag was passed to SPI_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, or 0 for no limit ๐Ÿ”ฅ
  • DestReceiver * dest โ€” DestReceiver object that will receive any tuples emitted by the query; if NULL, result tuples are accumulated into a SPI_tuptable structure, as in SPI_execute ๐Ÿ“ฌ
  • ResourceOwner owner โ€” This field is present for consistency with SPI_execute_plan_extended, but it is ignored, since the plan used by SPI_execute_extended is 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