Skip to content

Conversation

@pyramation
Copy link
Collaborator

No description provided.

This adds a new package for deparsing PL/pgSQL function ASTs back to SQL strings.
The PL/pgSQL AST is different from the regular SQL AST and represents the internal
structure of PL/pgSQL function bodies.

Supported constructs:
- Variable declarations (DECLARE section)
- Control flow (IF, CASE, LOOP, WHILE, FOR, FOREACH)
- Exception handling (BEGIN...EXCEPTION...END)
- Cursor operations (OPEN, FETCH, CLOSE)
- Return statements (RETURN, RETURN NEXT, RETURN QUERY)
- Dynamic SQL (EXECUTE)
- RAISE statements
- And more...

The deparser follows the same patterns as the existing pgsql-deparser package.
…rser

- Add @libpg-query/parser as dev dependency for parsing PL/pgSQL
- Create test-utils with fixture pipeline that loads from __fixtures__/plpgsql/
- Add jest.config.js for TypeScript support in tests
- Update tests to use real parser output instead of hardcoded JSON fixtures
- Tests now demonstrate proven pipeline: SQL fixtures -> parser -> deparser
- Add make-fixtures.ts script that generates fixtures from __fixtures__/plpgsql/
- Create generated.json with 176 valid PL/pgSQL statements (full SQL statements)
- Add comprehensive test-utils with cleanPlpgsqlTree for AST comparison
- Implement expectAstMatch for round-trip testing (parse -> deparse -> reparse)
- Add FixtureTestUtils class for loading and running fixture tests
- Update tests to use generated.json with proper round-trip validation
- Add 'fixtures' npm script to package.json
…ests

- Fix CALL statement deparser to avoid duplicate CALL keyword
- Improve loop variable detection to only exclude implicitly declared vars
  (variables where lineno matches the loop statement's lineno)
- Add plpgsql-pretty fixtures folder with sample SQL files
- Add PlpgsqlPrettyTest utility for snapshot testing
- Add snapshot tests for uppercase/lowercase formatting
@pyramation pyramation merged commit c3a9431 into main Dec 31, 2025
28 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