@@ -3614,6 +3614,7 @@ pub enum Statement {
36143614 /// 1. [Hive](https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl#LanguageManualDDL-Create/Drop/ReloadFunction)
36153615 /// 2. [PostgreSQL](https://www.postgresql.org/docs/15/sql-createfunction.html)
36163616 /// 3. [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_function_statement)
3617+ /// 4. [MsSql](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql)
36173618 CreateFunction ( CreateFunction ) ,
36183619 /// CREATE TRIGGER
36193620 ///
@@ -4060,6 +4061,12 @@ pub enum Statement {
40604061 ///
40614062 /// See: <https://learn.microsoft.com/en-us/sql/t-sql/statements/print-transact-sql>
40624063 Print ( PrintStatement ) ,
4064+ /// ```sql
4065+ /// RETURN [ expression ]
4066+ /// ```
4067+ ///
4068+ /// See [ReturnStatement]
4069+ Return ( ReturnStatement ) ,
40634070}
40644071
40654072#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
@@ -5752,6 +5759,7 @@ impl fmt::Display for Statement {
57525759 Ok ( ( ) )
57535760 }
57545761 Statement :: Print ( s) => write ! ( f, "{s}" ) ,
5762+ Statement :: Return ( r) => write ! ( f, "{r}" ) ,
57555763 Statement :: List ( command) => write ! ( f, "LIST {command}" ) ,
57565764 Statement :: Remove ( command) => write ! ( f, "REMOVE {command}" ) ,
57575765 }
@@ -8354,6 +8362,7 @@ impl fmt::Display for FunctionDeterminismSpecifier {
83548362///
83558363/// [BigQuery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_11
83568364/// [PostgreSQL]: https://www.postgresql.org/docs/15/sql-createfunction.html
8365+ /// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql
83578366#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
83588367#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
83598368#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
@@ -8382,6 +8391,22 @@ pub enum CreateFunctionBody {
83828391 ///
83838392 /// [BigQuery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_11
83848393 AsAfterOptions ( Expr ) ,
8394+ /// Function body with statements before the `RETURN` keyword.
8395+ ///
8396+ /// Example:
8397+ /// ```sql
8398+ /// CREATE FUNCTION my_scalar_udf(a INT, b INT)
8399+ /// RETURNS INT
8400+ /// AS
8401+ /// BEGIN
8402+ /// DECLARE c INT;
8403+ /// SET c = a + b;
8404+ /// RETURN c;
8405+ /// END
8406+ /// ```
8407+ ///
8408+ /// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql
8409+ MultiStatement ( Vec < Statement > ) ,
83858410 /// Function body expression using the 'RETURN' keyword.
83868411 ///
83878412 /// Example:
@@ -9230,6 +9255,41 @@ impl fmt::Display for PrintStatement {
92309255 }
92319256}
92329257
9258+ /// Return (MsSql)
9259+ ///
9260+ /// for Functions:
9261+ /// RETURN scalar_expression
9262+ ///
9263+ /// See <https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql>
9264+ ///
9265+ /// for Triggers:
9266+ /// RETURN
9267+ ///
9268+ /// See <https://learn.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql>
9269+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
9270+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
9271+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
9272+ pub struct ReturnStatement {
9273+ pub value : Option < ReturnStatementValue > ,
9274+ }
9275+
9276+ impl fmt:: Display for ReturnStatement {
9277+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
9278+ match & self . value {
9279+ Some ( ReturnStatementValue :: Expr ( expr) ) => write ! ( f, "RETURN {}" , expr) ,
9280+ None => write ! ( f, "RETURN" ) ,
9281+ }
9282+ }
9283+ }
9284+
9285+ /// Variants of a `RETURN` statement
9286+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
9287+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
9288+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
9289+ pub enum ReturnStatementValue {
9290+ Expr ( Expr ) ,
9291+ }
9292+
92339293#[ cfg( test) ]
92349294mod tests {
92359295 use super :: * ;
0 commit comments