Skip to content

Format PL/pgSQL ALIAS, RETURN NEXT, and FOR-over-query#9

Merged
gmr merged 2 commits into
mainfrom
fix/plpgsql-decl-formatting
Jun 15, 2026
Merged

Format PL/pgSQL ALIAS, RETURN NEXT, and FOR-over-query#9
gmr merged 2 commits into
mainfrom
fix/plpgsql-decl-formatting

Conversation

@gmr

@gmr gmr commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Summary

Companion to tree-sitter-postgres #42. Once the grammar parses the new PL/pgSQL constructs, the formatter still rendered three of them incorrectly:

  • ALIAS declarations dropped their target — username ALIAS FOR $1; became username;. Now emits the full name ALIAS FOR target form.
  • RETURN NEXT / RETURN QUERY dropped the NEXT/QUERY keyword (RETURN NEXT;RETURN;). Now emitted, including optional EXECUTE and a trailing expression.
  • FOR-over-query dropped the query text after IN because the formatter looked for a non-existent for_control node. Now takes the matched for_* variant (for_query/for_integer_range/for_cursor/for_dynamic) up to its nested LOOP keyword.

Adds regression tests covering all three plus multi-word types and DEFAULT.

⚠️ Blocked on tree-sitter-postgres 1.2.3

The new tests parse constructs that only the grammar in gmr/tree-sitter-postgres#42 understands. CI will be red until that PR is merged, released as 1.2.3, and the dependency here is bumped (tree-sitter-postgres = "1.2.3"). That dep bump is the final step before merge.

Verified locally against the #42 grammar (via a path patch): full suite green, all 23 previously-failing production functions format faithfully.

🤖 Generated with Claude Code

Once the grammar parses these constructs (tree-sitter-postgres #42),
the formatter still rendered them incorrectly:

- ALIAS declarations dropped their target (`username ALIAS FOR $1`
  became `username;`). Emit the full `name ALIAS FOR target` form.
- RETURN NEXT / RETURN QUERY dropped the NEXT/QUERY keyword. Emit it,
  including an optional EXECUTE and trailing expression.
- A FOR loop over a query dropped the query text after IN because it
  looked for a non-existent `for_control` node. Take the matched for_*
  variant up to its nested LOOP keyword instead.

Add regression tests. These pass once the dependency is bumped to the
tree-sitter-postgres release carrying #42 (1.2.3).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@gmr, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 28 minutes and 27 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 18939966-9f93-4925-bfad-7a0f3322cef4

📥 Commits

Reviewing files that changed from the base of the PR and between 1d1ca7d and 03f54a5.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • Cargo.toml
  • src/formatter/plpgsql.rs
  • tests/plpgsql_test.rs

Comment @coderabbitai help to get the list of available commands and usage tips.

Carries the PL/pgSQL grammar support (multi-word types, DEFAULT,
bare RETURN NEXT, ALIAS FOR $N) that the formatter changes in this
branch depend on. Unblocks the new regression tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gmr gmr merged commit 32e70ab into main Jun 15, 2026
3 checks passed
@gmr gmr deleted the fix/plpgsql-decl-formatting branch June 15, 2026 17:02
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.

1 participant