Skip to content

PostgreSQL: Support BEGIN ATOMIC function bodies - #2728

Open
LucaCappelletti94 wants to merge 3 commits into
mainfrom
upstream/begin-atomic-function-body
Open

LucaCappelletti94 wants to merge 3 commits into
mainfrom
upstream/begin-atomic-function-body

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

CREATE FUNCTION rejected the SQL-standard body that PostgreSQL 14 added. CREATE FUNCTION f() RETURNS INT LANGUAGE sql BEGIN ATOMIC SELECT 1; END failed with Expected: end of statement, found: BEGIN under both PostgreSqlDialect and GenericDialect, and pg_dump writes SQL functions with such bodies in exactly this form.

The PostgreSQL CREATE FUNCTION option loop now reads BEGIN ATOMIC and the statements up to END, and stores them in a new CreateFunctionBody::BeginAtomic variant that reuses BeginEndStatements. PostgreSQL writes no AS before the block, so a separate variant keeps it apart from the SQL Server AS BEGIN ... END body. A RETURN expr; inside the block parses as the existing Statement::Return.

@codecov-commenter

codecov-commenter commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.41%. Comparing base (e15e9ab) to head (a710be2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2728      +/-   ##
==========================================
+ Coverage   82.40%   82.41%   +0.01%     
==========================================
  Files          42       42              
  Lines       35342    35362      +20     
  Branches    35342    35362      +20     
==========================================
+ Hits        29122    29145      +23     
+ Misses       2678     2675       -3     
  Partials     3542     3542              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/begin-atomic-function-body branch 2 times, most recently from 9aef0bb to 565b633 Compare October 26, 2026 20:18
Comment thread src/parser/mod.rs
} else if self.parse_keyword(Keyword::RETURN) {
ensure_not_set(&body.function_body, "RETURN")?;
body.function_body = Some(CreateFunctionBody::Return(self.parse_expr()?));
} else if self.peek_keywords(&[Keyword::BEGIN, Keyword::ATOMIC]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PostgreSQL accepts the same body for procedures (CREATE PROCEDURE p() LANGUAGE sql BEGIN ATOMIC INSERT INTO t VALUES (1); END), which parse_create_procedure still rejects at AS. Fine as a follow-up.

@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/begin-atomic-function-body branch from 30d2371 to a710be2 Compare October 28, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants