Skip to content

Add spi_colnames/spi_coltypes/spi_coltypmods#3

Merged
jdatcmd merged 1 commit into
masterfrom
feature/spi-colmeta
Jul 7, 2026
Merged

Add spi_colnames/spi_coltypes/spi_coltypmods#3
jdatcmd merged 1 commit into
masterfrom
feature/spi-colmeta

Conversation

@jdatcmd

@jdatcmd jdatcmd commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes a PL/Python parity gap on SPI result introspection. Three accessors expose a result's column metadata as parallel Arrays over its columns — the counterparts of PL/Python's colnames / coltypes / coltypmods:

  • spi_colnames(result)Array of column names (Strings)
  • spi_coltypes(result)Array of column type OIDs (Integers; cast with oid::regtype in SQL)
  • spi_coltypmods(result)Array of column type modifiers (Integers; e.g. 14 for varchar(10), -1 when none)

They read from the result's tuple descriptor (skipping dropped columns) and follow plruby's existing spi_processed/spi_status convention (spi_*(result) globals). A result with no tuple set — a non-SELECT, such as a plain INSERT — has no columns, so each returns an empty Array, consistent with spi_fetch_row (which already only yields rows for SELECT results).

Testing

New sql/colmeta test: names/types/typmods for a SELECT, mapping the returned OIDs back through regtype, and the empty-array non-SELECT case. Full suite green on PG 12 and PG 18. Additive; no compatibility impact.

🤖 Generated with Claude Code

Expose a SPI result's column metadata as parallel Arrays over its
columns, the counterparts of PL/Python's colnames / coltypes /
coltypmods:

  - spi_colnames(result)  -> Array of column names (Strings)
  - spi_coltypes(result)  -> Array of column type OIDs (Integers)
  - spi_coltypmods(result)-> Array of column type modifiers (Integers)

Read from the result's tuple descriptor, skipping dropped columns. A
result with no tuple set (a non-SELECT, e.g. a plain INSERT) has no
columns, so each returns an empty Array -- consistent with spi_fetch_row,
which already only yields rows for SELECT results.

New sql/colmeta test; full suite green on PG 12 and 18.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jdatcmd jdatcmd merged commit eac7a68 into master Jul 7, 2026
9 checks passed
@jdatcmd jdatcmd deleted the feature/spi-colmeta branch July 7, 2026 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant