fix(plpgsql-deparser): preserve ALIAS FOR declarations#308
Closed
pyramation wants to merge 1 commit into
Closed
Conversation
…metadata
The parser (libpg_query 17-constructive) now serializes ALIAS declarations
as an aliases array on PLpgSQL_function ({name, varno, lineno}); previously
the alias name existed only in the compiler namespace and was dropped, so
deparsed bodies referenced undeclared names. Alias declarations are
interleaved with variable declarations by source lineno (variables first on
ties) so aliases of local variables follow their target's declaration.
Fixtures 61-63 cover positional-param, named-param/local-var, and OLD/NEW
trigger aliases. Requires @libpg-query/parser >= 17.8.1 (aliases field).
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Contributor
|
Superseded by #312, which was rebuilt fresh on current PG18 main and merged. Closing. |
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 the last known PL/pgSQL round-trip gap:
ALIAS FORdeclarations were dropped entirely (the alias lives only in the PL/pgSQL compiler's namespace, which libpg_query never serialized), so deparsed bodies referenced undeclared names:The fork (
constructive-io/libpg_query17-constructive+18-constructive) now records aliases from the grammar's ALIAS production and emits them onPLpgSQL_function:This PR teaches
plpgsql-deparserto consume that:PLpgSQL_aliastype ({name, varno, lineno}) onPLpgSQL_function.aliasesdeparseDeclareSectionemitsname ALIAS FOR <datums[varno].refname>;interleaved with variable declarations by sourcelineno(variables win ties), so an alias of a local variable follows its target's declarationALIAS FOR $1, named-param + local-var aliases (interleaving),ALIAS FOR old/newin triggers; snapshot tests indeparser-fixes.test.ts@libpg-query/parser≥ 17.8.1 (with thealiasesfield) — CI will fail on the ALIAS fixtures until that's published from the updated17-constructivepin. All suites pass locally against the locally-built WASM (deparser 713, transform 1126, plpgsql-deparser 109, plpgsql-parser 296, plpgsql-parse 57, parse 68).Link to Devin session: https://app.devin.ai/sessions/eeb8deba0c04475091df703c88877302
Requested by: @pyramation