SPI_FNUMBER(3)
π 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
- opensuse-leap 16.0: postgresql16-docs 16.15-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms