Skip to content

format_plpgsql drops block labels, compiler directives and cursor queries #69

Description

@gmr

format_plpgsql() has the silent-drop defect that #58 fixed for SQL. The guard added in #59 never exercises it, since CREATE FUNCTION re-lays out a body rather than formatting it. Run over the 41 PL/pgSQL bodies in the PostgreSQL 19 documentation corpus, 5 lose content in every style:

Dropped Example
Block labels <<outerblock>> DECLARE ... BEGIN ... END loses <<outerblock>>, so EXIT outerblock / outerblock.quantity name a block that no longer exists
Compiler directives #variable_conflict use_variable, #print_strict_params on
A bound cursor's query referrer_keys CURSOR IS SELECT * FROM cs_referrer_keys ORDER BY try_order; loses the whole query

One further body is not a fixed point (a second pass changes it).

Separately, one body fails to parse: OPEN $1 FOR SELECT * FROM table_1; (a positional parameter as the cursor variable). That is valid PL/pgSQL rejected by the tree-sitter-postgres grammar, so it is an upstream grammar gap rather than a libpgfmt bug.

Fix

  • Render the label, directive and cursor-query nodes in the PL/pgSQL formatter.
  • Extend tests/token_loss_test.rs to run format_plpgsql() over the corpus's PL/pgSQL bodies with the same three checks (no token loss, output re-parses, fixed point), so this class is covered.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions