SPI_FNUMBER(3)
π 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 toSPI_ERROR_NOATTRIBUTEto detect an error. do NOT just check whether the result is less than or equal to0β 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
- alpine 3.23: postgresql18-doc 18.6-r0 Β· PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 Β· PostgreSQL
- arch rolling: postgresql 18.6-4 Β· PostgreSQL
- fedora 43: postgresql-server-devel 18.6-1.fc43 Β· PostgreSQL
- fedora 43: postgresql-server-devel 18.6-1.fc43 Β· PostgreSQL
- fedora 44: postgresql-server-devel 18.6-1.fc44 Β· PostgreSQL
- fedora 44: postgresql-server-devel 18.6-1.fc44 Β· PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-doc-18 18.6-0ubuntu0.26.04.1 Β· PostgreSQL
- ubuntu stonking: postgresql-doc-18 18.6-3build2 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms