PL/Python-style $_SD and native bytea transform (bytea_plphp)#34
Merged
Conversation
Two PL/Python-parity features. PL/php already had the session-global GD equivalent ($_SHARED); this adds the two pieces it lacked. $_SD: a per-function static dictionary that persists across calls to the same function within a session and is private to it. Implemented by prepending "static $_SD = array();" to every generated wrapper: the wrapped function is compiled once per session so the static persists, and a CREATE OR REPLACE installs a fresh op_array so $_SD resets. No per-call C lifecycle. Covered by sql/sd.sql (persistence, per-function isolation, $_SD vs $_SHARED, reset-on-redefine, structured values). bytea_plphp: a new transform extension mapping bytea to a raw, binary-safe PHP string and back, mirroring PL/Python's bytea <-> bytes. The default text path routes bytea through byteaout/byteain (a "\x..." hex string) and truncates on embedded NULs; the transform passes the bytes themselves. Reuses the existing transform machinery, so it also applies in nested contexts (e.g. a bytea column in a composite result). Non-string returns are rejected with a clear error. Modelled on jsonb_plphp; varatt.h is included only on PG 16+ where the varlena macros moved out of postgres.h. Docs (language reference, PL/Perl and PL/Tcl comparison tables, README, CHANGELOG) and CI (bytea_plphp built and tested in the matrix and ASAN jobs, alongside jsonb_plphp) updated. Verified in the plphp-build container on PG 18 / PHP 8.3: all 26 core tests (incl. sd) plus jsonb, hstore, and bytea suites green. 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.
Closes the two PL/Python-parity gaps PL/php had. The session-global
GDequivalent already exists as
$_SHARED; this adds the per-function privatedictionary and the native
byteamapping.$_SD(per-function private data)Each function now has an
$_SDassociative array that persists across calls tothat function within a session and is private to it, the per-function
counterpart to session-global
$_SHARED. The pair mirrors PL/Python'sSD/GD.Implemented by prepending
static $_SD = array();to every generated wrapper.The wrapped function is compiled once per session, so the static persists across
calls; a
CREATE OR REPLACEinstalls a fresh op_array, so$_SDresets. Noper-call C lifecycle, no struct changes.
sql/sd.sqlcovers persistence across calls, per-function isolation,$_SDvs$_SHARED, reset-on-redefine, structured values, and use inside a trigger.bytea_plphp(native bytea transform)A new transform extension mapping
byteato a raw, binary-safe PHP string andback, mirroring PL/Python's
bytea<->bytes. The default text path routesbytea through
byteaout/byteain(a\x...hex string) and truncates onembedded NULs; the transform passes the bytes themselves.
Modelled on
jsonb_plphp, so it reuses the existing transform machinery andalso applies in nested contexts (a
byteacolumn in a composite result, etc.).Non-string returns are rejected with a clear error.
varatt.his included onlyon PG 16+, where the varlena macros moved out of
postgres.h.Docs / CI
Language reference (
$_SDsection,bytea_plphptransform section), PL/Perl andPL/Tcl comparison tables, README, and CHANGELOG (
[Unreleased]) updated.bytea_plphpis built and tested in both the CI matrix and the ASAN job,alongside
jsonb_plphp.Testing
Verified in the
plphp-buildcontainer on PG 18 / PHP 8.3: all 26 core tests(including the new
sd) plus thejsonb,hstore, andbyteasuites pass.The full PG 11-18 matrix runs here via CI.
🤖 Generated with Claude Code