@@ -577,13 +577,7 @@ impl<'a> Parser<'a> {
577577 Keyword::GRANT => self.parse_grant(),
578578 Keyword::REVOKE => self.parse_revoke(),
579579 Keyword::START => self.parse_start_transaction(),
580- // `BEGIN` is a nonstandard but common alias for the
581- // standard `START TRANSACTION` statement. It is supported
582- // by at least PostgreSQL and MySQL.
583580 Keyword::BEGIN => self.parse_begin(),
584- // `END` is a nonstandard but common alias for the
585- // standard `COMMIT TRANSACTION` statement. It is supported
586- // by PostgreSQL.
587581 Keyword::END => self.parse_end(),
588582 Keyword::SAVEPOINT => self.parse_savepoint(),
589583 Keyword::RELEASE => self.parse_release(),
@@ -618,6 +612,7 @@ impl<'a> Parser<'a> {
618612 // `COMMENT` is snowflake specific https://docs.snowflake.com/en/sql-reference/sql/comment
619613 Keyword::COMMENT if self.dialect.supports_comment_on() => self.parse_comment(),
620614 Keyword::PRINT => self.parse_print(),
615+ Keyword::RETURN => self.parse_return(),
621616 _ => self.expected("an SQL statement", next_token),
622617 },
623618 Token::LParen => {
@@ -4880,6 +4875,8 @@ impl<'a> Parser<'a> {
48804875 self.parse_create_macro(or_replace, temporary)
48814876 } else if dialect_of!(self is BigQueryDialect) {
48824877 self.parse_bigquery_create_function(or_replace, temporary)
4878+ } else if dialect_of!(self is MsSqlDialect) {
4879+ self.parse_mssql_create_function(or_replace, temporary)
48834880 } else {
48844881 self.prev_token();
48854882 self.expected("an object type after CREATE", self.peek_token())
@@ -5134,6 +5131,72 @@ impl<'a> Parser<'a> {
51345131 }))
51355132 }
51365133
5134+ /// Parse `CREATE FUNCTION` for [MsSql]
5135+ ///
5136+ /// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql
5137+ fn parse_mssql_create_function(
5138+ &mut self,
5139+ or_replace: bool,
5140+ temporary: bool,
5141+ ) -> Result<Statement, ParserError> {
5142+ let name = self.parse_object_name(false)?;
5143+
5144+ let parse_function_param =
5145+ |parser: &mut Parser| -> Result<OperateFunctionArg, ParserError> {
5146+ let name = parser.parse_identifier()?;
5147+ let data_type = parser.parse_data_type()?;
5148+ Ok(OperateFunctionArg {
5149+ mode: None,
5150+ name: Some(name),
5151+ data_type,
5152+ default_expr: None,
5153+ })
5154+ };
5155+ self.expect_token(&Token::LParen)?;
5156+ let args = self.parse_comma_separated0(parse_function_param, Token::RParen)?;
5157+ self.expect_token(&Token::RParen)?;
5158+
5159+ let return_type = if self.parse_keyword(Keyword::RETURNS) {
5160+ Some(self.parse_data_type()?)
5161+ } else {
5162+ return parser_err!("Expected RETURNS keyword", self.peek_token().span.start);
5163+ };
5164+
5165+ self.expect_keyword_is(Keyword::AS)?;
5166+ self.expect_keyword_is(Keyword::BEGIN)?;
5167+ let mut result = self.parse_statements()?;
5168+ // note: `parse_statements` will consume the `END` token & produce a Commit statement...
5169+ if let Some(Statement::Commit {
5170+ chain,
5171+ end,
5172+ modifier,
5173+ }) = result.last()
5174+ {
5175+ if *chain == false && *end == true && *modifier == None {
5176+ result = result[..result.len() - 1].to_vec();
5177+ }
5178+ }
5179+ let function_body = Some(CreateFunctionBody::MultiStatement(result));
5180+
5181+ Ok(Statement::CreateFunction(CreateFunction {
5182+ or_replace,
5183+ temporary,
5184+ if_not_exists: false,
5185+ name,
5186+ args: Some(args),
5187+ return_type,
5188+ function_body,
5189+ language: None,
5190+ determinism_specifier: None,
5191+ options: None,
5192+ remote_connection: None,
5193+ using: None,
5194+ behavior: None,
5195+ called_on_null: None,
5196+ parallel: None,
5197+ }))
5198+ }
5199+
51375200 fn parse_function_arg(&mut self) -> Result<OperateFunctionArg, ParserError> {
51385201 let mode = if self.parse_keyword(Keyword::IN) {
51395202 Some(ArgMode::In)
@@ -15063,6 +15126,13 @@ impl<'a> Parser<'a> {
1506315126 message: Box::new(self.parse_expr()?),
1506415127 }))
1506515128 }
15129+ /// Parse [Statement::Return]
15130+ fn parse_return(&mut self) -> Result<Statement, ParserError> {
15131+ let expr = self.parse_expr()?;
15132+ Ok(Statement::Return(ReturnStatement {
15133+ value: Some(ReturnStatementValue::Expr(expr)),
15134+ }))
15135+ }
1506615136
1506715137 /// Consume the parser and return its underlying token buffer
1506815138 pub fn into_tokens(self) -> Vec<TokenWithSpan> {
0 commit comments