fix: pg_query_parse_plpgsql() regressions in PG 18#1
Closed
pyramation wants to merge 1 commit into
Closed
Conversation
Three fixes for the PL/pgSQL JSON serialization:
1. Handle PLPGSQL_DTYPE_PROMISE datums in dump_function()
- PG 18 trigger functions create PROMISE datums for TG_* variables
- These were falling through to the default case, producing empty {}
with mismatched braces, resulting in malformed JSON output
- Fix: serialize PROMISE datums using dump_var() since they are
PLpgSQL_var structs
2. Support arbitrary schema names in LookupExplicitNamespace()
- PG 18 reworked PL/pgSQL compilation to use more original code,
which now calls LookupExplicitNamespace for schema-qualified types
- Previously only pg_catalog and public were supported, causing an
error for any other schema (e.g. "my_schema".users)
- Fix: return PG_PUBLIC_NAMESPACE for unknown schemas so type lookup
falls through to the RECORDOID path
3. Serialize retvarno field in dump_return() and dump_return_next()
- PG 18 compiler sets retvarno instead of expr for simple variable
returns (RETURN v, RETURN NEW in some cases)
- The retvarno field was commented out, so these returns lost their
target variable reference
- Fix: uncomment WRITE_INT_FIELD for retvarno
This was referenced May 22, 2026
This was referenced Jul 19, 2026
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
Fixes three regressions in
pg_query_parse_plpgsql()introduced by the PG 18 PL/pgSQL compilation rework. All three work correctly in17-6.1.0.Bug 1: Trigger functions produce malformed JSON
PG 18 trigger functions create
PLPGSQL_DTYPE_PROMISEdatums for TG_* variables (tg_name, tg_when, tg_level, etc.). Thedump_function()switch statement didn't handle this dtype, so each PROMISE datum produced an empty{}with mismatched closing braces — corrupting the entire JSON output.Fix: Add
PLPGSQL_DTYPE_PROMISEcase that serializes viadump_var()(PROMISE datums arePLpgSQL_varstructs).Bug 2: Schema-qualified types fail with "Not implemented"
The PG 18 compilation rework now calls
LookupExplicitNamespace()for schema-qualified variable types. This function only supportedpg_catalogandpublic, causing any other schema (e.g."my_schema".users) to error out.Fix: Return
PG_PUBLIC_NAMESPACEfor unknown schemas, so type lookup falls through to theRECORDOIDpath inGetSysCacheOid. The schema name is preserved in the PL/pgSQL type string.Bug 3:
RETURN <variable>loses its expressionPG 18's compiler sets
retvarnoinstead ofexprfor simple variable returns (RETURN v,RETURN NEW). Butretvarnowas commented out indump_return()anddump_return_next().Fix: Uncomment
WRITE_INT_FIELD(retvarno, retvarno, retvarno)in both functions.Changes (2 files, +14 / -4)
src/pg_query_json_plpgsql.c— Handle PROMISE datums, serialize retvarnosrc/postgres/src_backend_catalog_namespace.c— Support arbitrary schema names