SPI_CURSOR_PARSE_OPEN(3)

πŸ’– SPI_CURSOR_PARSE_OPEN πŸ’–

okay so bestie, welcome to the manual page for SPI_cursor_parse_open β€” it's the PostgreSQL 18.6 one, and it's genuinely iconic. Let's get into it 🫢


✨ NAME ✨

SPI_cursor_parse_open β€” set up a cursor using a query string and parameters 🌸


✨ SYNOPSIS ✨

Portal SPI_cursor_parse_open(const char *name,
                             const char *command,
                             const SPIParseOpenOptions * options)

no cap, that's the whole signature. three args, one Portal coming back πŸ’…


✨ DESCRIPTION ✨

So SPI_cursor_parse_open sets up a cursor (internally that's a portal, iykyk) that will execute the query string you hand it. Think of it as the glow-up version of SPI_prepare_cursor followed by SPI_cursor_open_with_paramlist β€” except the parameter references inside the query string are handled entirely by supplying a ParamListInfo object. no extra steps, no drama ✨

For one-time query execution, this function should be preferred over SPI_prepare_cursor followed by SPI_cursor_open_with_paramlist. But listen β€” if the same command is gonna be executed with many different parameters, either method might be faster. It literally depends on the cost of re-planning versus the benefit of custom plans. vibe check your use case, basically πŸ’€

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. periodt.

Also very important: the passed-in parameter data will be copied into the cursor's portal, so it can be freed while the cursor still exists. you can let that memory go, she's safe πŸŽ€


✨ ARGUMENTS ✨

  • const char * name β€” name for the portal, or NULL to let the system pick a name for you (main character energy, letting the system decide πŸ’…)
  • const char * command β€” the command string
  • const SPIParseOpenOptions * 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 get added to the struct in future will be defined to behave backwards-compatibly if they are zero. zero it first, queen πŸ‘‘

The currently available options fields are:

  • ParamListInfo params β€” data structure containing query parameter types and values; NULL if none
  • int cursorOptions β€” integer bit mask of cursor options; zero produces default behavior
  • bool read_only β€” true for read-only execution

✨ RETURN VALUE ✨

Pointer to the portal containing the cursor. πŸŽ€

⚠️ heads up bestie: there is no error return convention here. any error will be reported via elog. so don't go checking for a NULL return like it's gonna tell you something β€” it won't 😭

okay that's the whole page, you ate it πŸ’– stay slay, go set up those cursors.

PostgreSQL 18.6 🌈 Β· dated 2026 Β· that's a wrap on SPI_CURSOR_PARSE_OPEN(3), mwah πŸ’…βœ¨