-
Notifications
You must be signed in to change notification settings - Fork 601
Allow stored procedures to be defined without BEGIN
/END
#1834
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
base: main
Are you sure you want to change the base?
Conversation
src/parser/mod.rs
Outdated
let begin_token: AttachedToken = self | ||
.expect_keyword(Keyword::BEGIN) | ||
.map(AttachedToken) | ||
.unwrap_or_else(|_| AttachedToken::empty()); | ||
let statements = self.parse_statement_list(&[Keyword::END])?; | ||
let end_token = match &begin_token.0.token { | ||
Token::Word(w) if w.keyword == Keyword::BEGIN => { | ||
AttachedToken(self.expect_keyword(Keyword::END)?) | ||
} | ||
_ => AttachedToken::empty(), | ||
}; |
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.
Could also do it like this: https://github.com/apache/datafusion-sqlparser-rs/pull/1810/files#diff-6f6a082c3ddfc1f16cc4a455e3e2e2d2508f77b682ab18cabee69471bbb3edb3R244-R260, not sure which is best
src/ast/mod.rs
Outdated
body: Vec<Statement>, | ||
body: BeginEndStatements, |
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.
It it an abuse of BeginEndStatements to potentially have the begin/end token be empty? This could alternately be an enum of BeginEndStatements and Sequence, similar to elsewhere
- similar to functions & procedures, this dialect can define triggers with a multi statement block - there's no `EXECUTE` keyword here, so that means the `exec_body` used by other dialects becomes an `Option`, and our `statements` is also optional for them
- formerly, a semicolon after the last statement in a procedure was non-canonical (because they were added via `join`); a `BeginEndStatements` statements list will always write them out - `BeginEndStatements` begin/end tokens won't be written when empty - EOF now concludes parsing a statement list
dd8382e
to
ffd3b6a
Compare
I have temporarily rebased this branch on #1810 to pick up the new helper function and similarly use the enum pattern to distinguish between Sequence & BeginEndStatements. |
…tokens - this further consolidates with existing patterns
ffd3b6a
to
038d3c2
Compare
For SQL Server, you can make a stored procedure without begin/end (docs ref). Otherwise, it parses the same way.
To differentiate with/without in the parser, the stored procedure struct's
statements
field was changed fromVec<Statement>
(where begin/end are required & implicit) to aBeginEndStatements
, where the begin/end tokens are explicit. They're empty when missing & written when present.This PR also includes the fix to allow EOF to end a statement list from #1831 (so whichever merges first, I'll rebase accordingly)
The diff is perhaps larger than expected due to the question of canonical semicolons for procedure statement bodies. Formerly, a semicolon after the last statement in a procedure was non-canonical (because they were added via
join
... so perhaps not particular intentional for it to have been that way); aBeginEndStatements
statements list will always write them out.An additional test case example without begin/end has been added as well.