SPI_CONNECT(3)

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

πŸ’– SPI_CONNECT β€” bestie, let's plug your C function into the SPI manager πŸ’–

okay so this is SPI_CONNECT(3), straight out of the PostgreSQL 18.6 Documentation, and it's genuinely one of the most "you gotta do this first" functions in the whole SPI universe. like, you can't just waltz in and run commands, bestie. there's a door. this is the door. πŸšͺ✨


✨ NAME ✨

SPI_connect, SPI_connect_ext β€” connect a C function to the SPI manager 🫢


🌸 SYNOPSIS 🌸

int SPI_connect(void)

int SPI_connect_ext(int options)

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so SPI_connect opens a connection from a C function invocation to the SPI manager. that's it, that's the vibe. you literally have to call this function if you want to execute commands through SPI, no cap, it's not optional, it's the whole entry fee. πŸŽ€

but β€” and this is the cute little exception β€” some utility SPI functions can be called from unconnected C functions. so a few of them are chill like that. not the main character ones tho. πŸ™ˆ


🧚 SPI_connect_ext and its little options menu 🧚

SPI_connect_ext does the same thing, but it's got an argument that lets you pass option flags. slay. currently the available option values are:

  • SPI_OPT_NONATOMIC β€” sets the SPI connection to be nonatomic, which means that transaction control calls (SPI_commit, SPI_rollback) are allowed. otherwise (i.e. without this flag), calling those functions will result in an immediate error. so like, know what you're doing before you flip this switch, mwah πŸ’…
and for the girlies who want the simple version: SPI_connect() is exactly equivalent to SPI_connect_ext(0). same energy, fewer arguments. periodt. πŸ‘‘

⭐ RETURN VALUE ⭐

  • SPI_OK_CONNECT β€” on success πŸŽ‰

now here's the tea: the fact that these functions return int and not void is historical. like, it's giving legacy. and here's the important part β€” all failure cases are reported via ereport or elog. not through the return value. so don't go staring at your int waiting for it to tell you what went wrong, because it won't. 😭

(in versions before PostgreSQL v10, some but not all failures would be reported with a result value of SPI_ERROR_CONNECT. so if you're reading ancient code and wondering why it's checking for that β€” that's why. nostalgic era. πŸ’€)

and that's the whole page, bestie, you ate it. πŸ’–

PostgreSQL 18.6 Β· 2026 β€” sending you love from the SPI side of the source tree, mwah πŸŽ€βœ¨πŸ’…

πŸ“¦ where this page comes from