fix: handle BEGIN ATOMIC syntax in SQL-standard function bodies#244
Merged
fix: handle BEGIN ATOMIC syntax in SQL-standard function bodies#244
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>
Contributor
There was a problem hiding this comment.
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>
Contributor
There was a problem hiding this comment.
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.
alecthomas
pushed a commit
to alecthomas/pgschema
that referenced
this pull request
Jan 26, 2026
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #241
Functions using BEGIN ATOMIC (SQL-standard multi-statement body, PG14+) were incorrectly wrapped with AS$$...$$ delimiters, producing invalid SQL.