SPI_FNUMBER(3)

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

πŸ’… SPI_fnumber πŸ’…

okay so this is the SPI_fnumber page from the PostgreSQL 16.15 docs, and it's lowkey iconic for one very specific job: finding the column number for a column name πŸ’– bestie, let's get into it.


✨ NAME ✨

SPI_fnumber β€” determine the column number for the specified column name. Like, you give it a name, it gives you the number. Slay πŸ”₯


πŸ¦‹ SYNOPSIS πŸ¦‹

int SPI_fnumber(TupleDesc rowdesc, const char * colname)

🌸 DESCRIPTION 🌸

okay so SPI_fnumber returns the column number for the column with the specified name. That's the whole vibe ✨

if colname refers to a system column (e.g., ctid) then the appropriate negative column number will be returned. Not a typo, bestie β€” negative numbers are absolutely possible here πŸ™ˆ

so the caller should be careful to test the return value for exact equality to SPI_ERROR_NOATTRIBUTE to detect an error. Testing the result for less than or equal to 0 is not correct unless system columns should be rejected. Like, do not just do <= 0 unless you actually mean to reject system columns, okay? This is important, no cap πŸ’€


πŸŽ€ ARGUMENTS πŸŽ€

  • TupleDesc rowdesc β€” input row description. The row description you're passing in, bestie πŸ“₯
  • const char * colname β€” column name. The name you're hunting for πŸ”

πŸ‘‘ RETURN VALUE πŸ‘‘

Column number (count starts at 1 for user-defined columns), or SPI_ERROR_NOATTRIBUTE if the named column was not found. So yes: user-defined columns start counting at 1, and if the named column is not found, you get SPI_ERROR_NOATTRIBUTE back πŸ’– periodt.


xoxo, this has been the SPI_fnumber(3) page from the PostgreSQL 16.15 docs, dated 2026 β€” go forth and find those columns, bestie πŸ«ΆπŸ’…βœ¨

πŸ“¦ where this page comes from