feat(plpgsql-deparser): add context-based RETURN statement handling #267
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.
feat(plpgsql-deparser): add context-based RETURN statement handling
Summary
This PR adds context-based RETURN statement handling to the PL/pgSQL deparser. PostgreSQL requires different RETURN syntax based on function return type:
RETURNis validRETURN NULLis required for empty returnsPreviously, the deparser always output bare
RETURNfor empty return statements. Now, callers can passReturnInfocontext to get correct output based on the function's return type.Key changes:
ReturnInfotype with kinds:void,setof,trigger,scalar,out_paramsdeparseReturn()to use context when available, defaulting to bareRETURNfor backward compatibilitygetReturnInfo()helper inplpgsql-parserto extract return type fromCreateFunctionStmtASTThe snapshot changes reflect previous PERFORM/INTO fixes from PR #266 that were merged to main.
Updates since last revision
Latest: Added plpgsql-parser and plpgsql-deparser to CI workflow
Previous: Added 14 regression fixtures from constructive-db PR #229
__fixtures__/plpgsql/plpgsql_deparser_fixes.sqlwith real-world-inspired test casesgenerated.json: now 190 valid statements (up from 176)Previous: Comprehensive round-trip testing for ALL generated fixtures
plpgsql-generated/generated.jsonpg_catalog.pg_class%rowtype[]→pg_class%rowtype[])$tag$...$tag$not supported)Review & Testing Checklist for Human
getReturnInfo()logic inpackages/plpgsql-parser/src/return-info.ts- ensure the AST parsing correctly identifies all return type scenarios (especially edge cases likeRETURNS TABLEvsOUTparams)mainbranch too, not just this PRplpgsql-parserandplpgsql-deparserjobs appear in the workflow run__fixtures__/plpgsql/plpgsql_deparser_fixes.sql- verify they cover the patterns that required fixes in constructive-dbSuggested test plan:
pnpm testinpackages/plpgsql-deparserandpackages/plpgsql-parserRETURN NULLwhen context is providedRETURNNotes
This is patch 4 from constructive-db PR #229, implementing a context-passing approach instead of heuristics for RETURN handling.
Link to Devin run: https://app.devin.ai/sessions/8e1c971e9b194cd9a7dda034c89bd74b
Requested by: Dan Lynch (@pyramation)