Apply jsonb/hstore transforms in nested contexts (triggers, composites, SETOF)#30
Merged
Conversation
…s, SETOF) Previously a declared TRANSFORM FOR TYPE applied only to a function's top-level scalar arguments and result. Now it also converts values of that type nested inside rows, in both directions: - FROM SQL: a trigger's $_TD['new']/['old'] columns and composite argument fields arrive as native PHP values (e.g. jsonb/hstore as PHP arrays). - TO SQL: composite/record result fields, RETURNS SETOF / return_next rows, RETURNS TABLE columns, and the 'MODIFY' trigger return are built from native PHP values. Mechanism: the function's declared transform types (protrftypes) are stored on the compiled descriptor for every function (triggers included) and threaded into the tuple builders as an explicit plphp_trans_ctx. FROM-side columns are converted by calling the FromSQL transform directly; TO-side columns run the ToSQL transform to a Datum and render it to text for the existing BuildTupleFromCStrings path (no tuple-mechanism rewrite). Rows read back through SPI are passed a NULL context and stay in text form, matching PL/Ruby. Verified on PostgreSQL 18: new nested-context cases in both hstore_plphp and jsonb_plphp, plus the full plphp suite -- all green (25 / 1 / 1). 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.
Follow-up to #29. Closes the one item deferred there: a
TRANSFORM FOR TYPE(jsonb_plphp/hstore_plphp) previously applied only to a function's top-level scalar arguments and result. Now it also converts values of that type nested inside rows, in both directions — matching PL/Ruby.Built and tested on PostgreSQL 18 / PHP 8.3; all suites green (25 plphp,
jsonb_plphp,hstore_plphp).What now transforms
FROM SQL (value → PHP):
$_TD['new']/$_TD['old']columnsTO SQL (PHP → value):
RETURNS SETOF/return_nextrows (includingRETURNS SETOF hstore)RETURNS TABLE(...)columns'MODIFY'Unchanged: rows read back through SPI (
spi_exec/spi_fetch_row/cursors) stay in text form, exactly as PL/Ruby leaves them.How
pg_proc.protrftypes) are now resolved for every function (triggers included) and stored on the compiled descriptor (lang_oid+trftypes).plphp_trans_ctx(language + declared types) is threaded explicitly into the tuple builders — not via a global — so the SPI path can opt out by passing no context. The SRFreturn_nextpath uses acurrent_trans_ctxset alongside the existingcurrent_*SRF globals.BuildTupleFromCStringspath re-parses it — no rewrite of the tuple-building mechanism, keeping the change low-risk. Non-transform columns are byte-for-byte unchanged.Testing
New nested-context cases added to both
hstore_plphpandjsonb_plphpregression suites (trigger MODIFY, composite arg/result, SETOF, TABLE, plus an assertion that SPI-read rows are not transformed). Expected files generated from real runs. No existing expected output changed.🤖 Generated with Claude Code