@@ -3610,6 +3610,7 @@ pub enum Statement {
36103610 /// 1. [Hive](https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl#LanguageManualDDL-Create/Drop/ReloadFunction)
36113611 /// 2. [PostgreSQL](https://www.postgresql.org/docs/15/sql-createfunction.html)
36123612 /// 3. [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_function_statement)
3613+ /// 4. [MsSql](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql)
36133614 CreateFunction ( CreateFunction ) ,
36143615 /// CREATE TRIGGER
36153616 ///
@@ -4050,6 +4051,13 @@ pub enum Statement {
40504051 arguments : Vec < Expr > ,
40514052 options : Vec < RaisErrorOption > ,
40524053 } ,
4054+ /// Return (Mssql)
4055+ ///
4056+ /// for Functions:
4057+ /// RETURN scalar_expression
4058+ ///
4059+ /// See: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql
4060+ Return ( ReturnStatement ) ,
40534061}
40544062
40554063#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
@@ -5736,7 +5744,11 @@ impl fmt::Display for Statement {
57365744 write ! ( f, " WITH {}" , display_comma_separated( options) ) ?;
57375745 }
57385746 Ok ( ( ) )
5739- }
5747+ } ,
5748+ Statement :: Return ( r) => {
5749+ write ! ( f, "{r}" ) ?;
5750+ Ok ( ( ) )
5751+ } ,
57405752
57415753 Statement :: List ( command) => write ! ( f, "LIST {command}" ) ,
57425754 Statement :: Remove ( command) => write ! ( f, "REMOVE {command}" ) ,
@@ -8340,6 +8352,7 @@ impl fmt::Display for FunctionDeterminismSpecifier {
83408352///
83418353/// [BigQuery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_11
83428354/// [PostgreSQL]: https://www.postgresql.org/docs/15/sql-createfunction.html
8355+ /// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql
83438356#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
83448357#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
83458358#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
@@ -8368,6 +8381,22 @@ pub enum CreateFunctionBody {
83688381 ///
83698382 /// [BigQuery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_11
83708383 AsAfterOptions ( Expr ) ,
8384+ /// Function body with statements before the `RETURN` keyword.
8385+ ///
8386+ /// Example:
8387+ /// ```sql
8388+ /// CREATE FUNCTION my_scalar_udf(a INT, b INT)
8389+ /// RETURNS INT
8390+ /// AS
8391+ /// BEGIN
8392+ /// DECLARE c INT;
8393+ /// SET c = a + b;
8394+ /// RETURN c;
8395+ /// END;
8396+ /// ```
8397+ ///
8398+ /// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql
8399+ MultiStatement ( Vec < Statement > ) ,
83718400 /// Function body expression using the 'RETURN' keyword.
83728401 ///
83738402 /// Example:
@@ -9203,6 +9232,30 @@ pub enum CopyIntoSnowflakeKind {
92039232 Location ,
92049233}
92059234
9235+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
9236+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
9237+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
9238+ pub struct ReturnStatement {
9239+ pub value : Option < ReturnStatementValue > ,
9240+ }
9241+
9242+ impl fmt:: Display for ReturnStatement {
9243+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
9244+ match & self . value {
9245+ Some ( ReturnStatementValue :: Expr ( expr) ) => write ! ( f, "RETURN {}" , expr) ,
9246+ None => write ! ( f, "RETURN" )
9247+ }
9248+ }
9249+ }
9250+
9251+ /// Variants of the Mssql `RETURN` statement
9252+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
9253+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
9254+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
9255+ pub enum ReturnStatementValue {
9256+ Expr ( Expr ) ,
9257+ }
9258+
92069259#[ cfg( test) ]
92079260mod tests {
92089261 use super :: * ;
0 commit comments