Skip to content

Conversation

@pyramation
Copy link
Collaborator

@pyramation pyramation commented Jan 7, 2026

Summary

The plpgsql-parser now automatically extracts return type information from CreateFunctionStmt and passes it to the PL/pgSQL deparser. This ensures correct RETURN statement handling without users needing to manually provide return context.

Behavior:

  • SETOF functions: bare RETURN; stays as RETURN;
  • Scalar functions: empty RETURN; becomes RETURN NULL;
  • Void functions: bare RETURN; stays as RETURN;
  • Trigger functions: handled correctly
  • OUT parameter functions: bare RETURN; stays as RETURN;

Updates since last revision

Documentation updates to clarify the separation between packages:

  • plpgsql-deparser README: Now clearly states it's a "body-only" deparser and directs users to plpgsql-parser for full SQL + PL/pgSQL deparsing
  • plpgsql-parser README: Updated to emphasize it handles "heterogeneous parsing and deparsing" - the full pipeline for complete CREATE FUNCTION statements

Previous updates:

  • round-trip.test.ts: New test file that runs all 190 generated fixtures through the full plpgsql-parser.parse()plpgsql-parser.deparseSync() → reparse → compare AST pipeline
  • This ensures regressions in the automatic return info handling will be caught by fixtures (not just explicit unit tests)
  • All 190 fixtures pass round-trip testing through plpgsql-parser

Review & Testing Checklist for Human

  • Verify the if (plpgsqlFunc) guard in deparse.ts doesn't silently skip function body stitching - if dehydrated.plpgsql_funcs?.[0]?.PLpgSQL_function is undefined when it shouldn't be, the function body won't be updated
  • Test with a real PL/pgSQL function that has an empty RETURN in a scalar context to confirm it outputs RETURN NULL
  • Verify the cleanSqlTree function in round-trip tests strips only location metadata and doesn't mask real AST differences
  • Review README changes for accuracy - ensure the package separation guidance is clear and correct

Recommended test plan: Run pnpm test in packages/plpgsql-parser to verify all 92 tests pass (including the new round-trip tests that exercise all 190 fixtures).

Notes

…ETURN handling

The deparser now automatically extracts return type information from the
CreateFunctionStmt and passes it to the PL/pgSQL deparser. This ensures
correct RETURN statement handling without users needing to manually
provide return context:

- SETOF functions: bare RETURN stays as RETURN
- Scalar functions: empty RETURN becomes RETURN NULL
- Void functions: bare RETURN stays as RETURN
- Trigger functions: handled correctly
- OUT parameter functions: bare RETURN stays as RETURN

Added 5 tests to verify automatic return info handling works correctly.
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit a1f8a49 into main Jan 7, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants