SPI_FNUMBER(3)

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

πŸ’– NAME πŸ’–

SPI_fnumber β€” bestie, this is the one that figures out the column number for a column when all you've got is its name πŸŽ€


✨ SYNOPSIS ✨

int SPI_fnumber(TupleDesc rowdesc, const char * colname)

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the vibe: SPI_fnumber hands you back the column number for the column with the name you specified. that's it, that's the whole job πŸ’…

but wait, plot twist πŸ‘€ β€” if colname is pointing at a system column (think like ctid and friends), then you're getting the appropriate negative column number back. not a bug, that's just how it is, no cap.

⚠️ listen up bestie, this part matters ⚠️ the caller has to be careful and test the return value for exact equality to SPI_ERROR_NOATTRIBUTE to detect an error. do NOT just check whether the result is less than or equal to 0 β€” that is not correct, unless rejecting system columns is literally what you want. fr fr, this is the trap that eats people πŸͺ€

🌸 ARGUMENTS 🌸

  • TupleDesc rowdesc β€” the input row description, aka the row you're snooping through πŸ”
  • const char * colname β€” the column name you're hunting for πŸ‘‘

πŸ‘‘ RETURN VALUE πŸ‘‘

you get the column number back (and btw the count starts at 1 for user-defined columns, not 0, so don't come at me with zero-indexed energy πŸ’€), or you get SPI_ERROR_NOATTRIBUTE if the named column was nowhere to be found 😭


that's the whole page, you ate that 🫢 go forth and check your return values properly, i'm literally begging you πŸ’œ

sending love from the PostgreSQL 18.6 docs, dated 2026 ✨ mwah πŸ’–

πŸ“¦ where this page comes from