Add spi_colnames/spi_coltypes/spi_coltypmods#3
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'scolnames/coltypes/coltypmods:spi_colnames(result)→Arrayof column names (Strings)spi_coltypes(result)→Arrayof column type OIDs (Integers; cast withoid::regtypein SQL)spi_coltypmods(result)→Arrayof column type modifiers (Integers; e.g.14forvarchar(10),-1when none)They read from the result's tuple descriptor (skipping dropped columns) and follow plruby's existing
spi_processed/spi_statusconvention (spi_*(result)globals). A result with no tuple set — a non-SELECT, such as a plainINSERT— has no columns, so each returns an emptyArray, consistent withspi_fetch_row(which already only yields rows forSELECTresults).Testing
New
sql/colmetatest: names/types/typmods for aSELECT, mapping the returned OIDs back throughregtype, and the empty-array non-SELECTcase. Full suite green on PG 12 and PG 18. Additive; no compatibility impact.🤖 Generated with Claude Code