PG17: Serialize retvarno and out_param_varno in PL/pgSQL parse output - #356
Open
pyramation wants to merge 2 commits into
Open
PG17: Serialize retvarno and out_param_varno in PL/pgSQL parse output#356pyramation wants to merge 2 commits into
pyramation wants to merge 2 commits into
Conversation
…JSON output Backport of the PG 18 fix (pganalyze#355 fix 3) to 17: retvarno was commented out in dump_return/dump_return_next, so variable returns like RETURN NEXT r lost the returned variable entirely. Emit it only when >= 0 (-1 means the return uses expr instead of a datum). Golden plpgsql_samples.expected.json regenerated.
…istinguish bare RETURN NEXT with OUT params
Member
|
@pyramation Thanks for the contribution! Can you remind me why you opened this against 17? Is that because of the current challenges with PL/pgSQL parsing on the 18 branch, and this way you're unblocked on having this working? |
Contributor
Author
|
I was doing it to keep things in sync, but we can close this and focus on 18 from here on out. I'm fine with 18 :) |
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.
I built and tested this against the full 23,000 statements in pgsql-parser, and a slew of other tests...
The JSON output of
pg_query_parse_plpgsqlomits two fields needed to faithfully reconstruct RETURN / RETURN NEXT statements:PLpgSQL_stmt_return.retvarno/PLpgSQL_stmt_return_next.retvarno— without it,RETURN NEXT <variable>is indistinguishable from a bareRETURN NEXT;, so any consumer round-tripping the AST back to source drops the returned variable.PLpgSQL_function.out_param_varno— needed to tell the two apart in OUT-parameter functions, where the compiler setsretvarnoimplicitly even for a bareRETURN NEXT;(and where emitting the variable name back is invalid syntax).This adds both fields to the serialized output. Existing output is unchanged except for the added keys.