SPI_PREPARE_CURSOR(3)

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

hii bestie, you're looking at SPI_PREPARE_CURSOR(3) from the PostgreSQL 13.23 docs, and tbh it's lowkey a glow-up for prepared statements πŸ’…βœ¨

πŸŽ€ NAME πŸŽ€

SPI_prepare_cursor β€” prepare a statement, without executing it yet 🫢

✨ SYNOPSIS ✨

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

🌸 DESCRIPTION 🌸

okay so SPI_prepare_cursor is literally identical to SPI_prepare, except it also lets you specify the planner's cursor options parameter. icon behavior fr fr.

That parameter is a bit mask, and its values are shown in nodes/parsenodes.h for the options field of DeclareCursorStmt. Meanwhile, plain old SPI_prepare always takes the cursor options as zero β€” no extra flair there, bestie.

πŸ’– ARGUMENTS πŸ’–

  • const char * command β€” the command string, aka the actual SQL vibe you're preparing πŸ’«
  • int nargs β€” number of input parameters ($1, $2, etc.) πŸŽ€
  • Oid * argtypes β€” pointer to an array containing the OIDs of the data types of the parameters πŸ‘‘
  • int cursorOptions β€” integer bit mask of cursor options; zero produces default behavior 🌈

πŸ¦‹ RETURN VALUE πŸ¦‹

SPI_prepare_cursor has the same return conventions as SPI_prepare. no cap, it keeps that same energy.

πŸ”₯ 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
bestie, note in particular that CURSOR_OPT_HOLD is ignored πŸ’€ like it did not make the cut.

big kiss from the PostgreSQL 13.23 docs, dated 2025 β€” mwah πŸ’‹πŸ’–

πŸ“¦ where this page comes from