-
Notifications
You must be signed in to change notification settings - Fork 29
fix: handle BEGIN ATOMIC syntax in SQL-standard function bodies #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Functions using BEGIN ATOMIC (SQL-standard multi-statement body, PG14+) were incorrectly wrapped with AS $$...$$ delimiters, producing invalid SQL. - Add check for BEGIN ATOMIC prefix alongside existing RETURN check - Apply same fix to procedures - Add test case with add_with_tax function using BEGIN ATOMIC syntax Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes issue #241 where PostgreSQL functions and procedures using the SQL-standard BEGIN ATOMIC syntax (introduced in PostgreSQL 14) were incorrectly wrapped with AS $$ ... $$ delimiters, producing invalid SQL.
Changes:
- Extended the SQL-standard body detection to recognize
BEGIN ATOMICsyntax in addition to the existingRETURNclause detection - Applied the fix to both functions (function.go) and procedures (procedure.go)
- Added test case demonstrating the fix with an
add_with_taxfunction usingBEGIN ATOMICsyntax
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/diff/function.go | Added BEGIN ATOMIC detection to prevent wrapping SQL-standard function bodies with AS $$ delimiters |
| internal/diff/procedure.go | Added BEGIN ATOMIC detection to prevent wrapping SQL-standard procedure bodies with AS $$ delimiters |
| testdata/diff/create_function/add_function/new.sql | Added test function using BEGIN ATOMIC syntax to reproduce issue #241 |
| testdata/diff/create_function/add_function/plan.txt | Updated expected plan output to include the new add_with_tax function |
| testdata/diff/create_function/add_function/plan.sql | Updated expected SQL output showing correct BEGIN ATOMIC formatting without AS $$ wrapper |
| testdata/diff/create_function/add_function/plan.json | Updated expected JSON plan to include the new function creation step |
| testdata/diff/create_function/add_function/diff.sql | Updated expected diff output showing the new function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Clarify comment in procedure.go that RETURN check is for consistency with function handling, not for procedure return values - Add test case for procedures with BEGIN ATOMIC syntax (validate_input) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ex#244) * fix: handle BEGIN ATOMIC syntax in SQL-standard function bodies (pgplex#241) Functions using BEGIN ATOMIC (SQL-standard multi-statement body, PG14+) were incorrectly wrapped with AS $$...$$ delimiters, producing invalid SQL. - Add check for BEGIN ATOMIC prefix alongside existing RETURN check - Apply same fix to procedures - Add test case with add_with_tax function using BEGIN ATOMIC syntax Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore: address PR review feedback - Clarify comment in procedure.go that RETURN check is for consistency with function handling, not for procedure return values - Add test case for procedures with BEGIN ATOMIC syntax (validate_input) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Fix #241
Functions using BEGIN ATOMIC (SQL-standard multi-statement body, PG14+) were incorrectly wrapped with AS$$...$$ delimiters, producing invalid SQL.