SPI_PREPARE_CURSOR(3)

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

โœจ SPI_prepare_cursor(3) โœจ

Okay bestie, gather round ๐Ÿ’– this page is literally about preparing a statement and not executing it yet. Itโ€™s giving โ€œprep now, run laterโ€ energy. No cap.


๐ŸŽ€ NAME ๐ŸŽ€

SPI_prepare_cursor โ€” prepare a statement, without executing it yet. Thatโ€™s the whole vibe: prep the statement, do not run it yet, periodt.

โœจ SYNOPSIS โœจ

SPIPlanPtr SPI_prepare_cursor(const char * command, int nargs,
                              Oid * argtypes, int cursorOptions)

๐Ÿ’– DESCRIPTION ๐Ÿ’–

SPI_prepare_cursor is identical to SPI_prepare, except it also lets you specify the plannerโ€™s โ€œcursor optionsโ€ parameter. Yes, thatโ€™s the extra little sparkle โœจ.

That parameter is a bit mask, and its values are the ones shown in nodes/parsenodes.h for the options field of DeclareCursorStmt. Meanwhile, SPI_prepare always takes the cursor options as zero โ€” no options, just zero, default behavior.

๐Ÿšจ Important: this function is now deprecated in favor of SPI_prepare_extended. Like, itโ€™s still a thing, but itโ€™s not the main character anymore. Choose SPI_prepare_extended if youโ€™re starting fresh. ๐Ÿ’…

๐Ÿฆ‹ ARGUMENTS ๐Ÿฆ‹

  • const char * command โ€” the command string. Itโ€™s a string, bestie.
  • int nargs โ€” number of input parameters ($1, $2, etc.). Count them, donโ€™t guess.
  • Oid * argtypes โ€” pointer to an array containing the OIDs of the data types of the parameters. Itโ€™s a pointer, it points at the OID array, you got this.
  • int cursorOptions โ€” integer bit mask of cursor options; zero produces default behavior. Zero = default. Simple as that.

๐ŸŒˆ RETURN VALUE ๐ŸŒˆ

SPI_prepare_cursor has the same return conventions as SPI_prepare. So if you know how SPI_prepare returns, thatโ€™s the exact same deal here. No new drama.

๐Ÿ’… NOTES ๐Ÿ’…

Useful bits to set in cursorOptions include:

  • CURSOR_OPT_SCROLL
  • CURSOR_OPT_NO_SCROLL
  • CURSOR_OPT_FAST_PLAN
  • CURSOR_OPT_GENERIC_PLAN
  • CURSOR_OPT_CUSTOM_PLAN

And note in particular that CURSOR_OPT_HOLD is ignored. Not โ€œhandled differently,โ€ not โ€œextra specialโ€ โ€” ignored. So donโ€™t come for CURSOR_OPT_HOLD, okay? ๐Ÿ™ˆ


Signed, sealed, and slayed by PostgreSQL 14.24 Documentation, dated 2026. Thatโ€™s the source/version and date, bestie, right at the bottom where it belongs. ๐Ÿซถ

๐Ÿ“ฆ where this page comes from