@@ -81,7 +81,8 @@ pub use self::query::{
8181 TableIndexType , TableSample , TableSampleBucket , TableSampleKind , TableSampleMethod ,
8282 TableSampleModifier , TableSampleQuantity , TableSampleSeed , TableSampleSeedModifier ,
8383 TableSampleUnit , TableVersion , TableWithJoins , Top , TopQuantity , UpdateTableFromKind ,
84- ValueTableMode , Values , WildcardAdditionalOptions , With , WithFill ,
84+ ValueTableMode , Values , WildcardAdditionalOptions , With , WithFill , XmlNamespaceDefinition ,
85+ XmlPassingArgument , XmlPassingClause , XmlTableColumn , XmlTableColumnOption ,
8586} ;
8687
8788pub use self :: trigger:: {
@@ -2292,18 +2293,14 @@ pub enum ConditionalStatements {
22922293 /// SELECT 1; SELECT 2; SELECT 3; ...
22932294 Sequence { statements : Vec < Statement > } ,
22942295 /// BEGIN SELECT 1; SELECT 2; SELECT 3; ... END
2295- BeginEnd {
2296- begin_token : AttachedToken ,
2297- statements : Vec < Statement > ,
2298- end_token : AttachedToken ,
2299- } ,
2296+ BeginEnd ( BeginEndStatements ) ,
23002297}
23012298
23022299impl ConditionalStatements {
23032300 pub fn statements ( & self ) -> & Vec < Statement > {
23042301 match self {
23052302 ConditionalStatements :: Sequence { statements } => statements,
2306- ConditionalStatements :: BeginEnd { statements , .. } => statements,
2303+ ConditionalStatements :: BeginEnd ( bes ) => & bes . statements ,
23072304 }
23082305 }
23092306}
@@ -2317,12 +2314,41 @@ impl fmt::Display for ConditionalStatements {
23172314 }
23182315 Ok ( ( ) )
23192316 }
2320- ConditionalStatements :: BeginEnd { statements, .. } => {
2321- write ! ( f, "BEGIN " ) ?;
2322- format_statement_list ( f, statements) ?;
2323- write ! ( f, " END" )
2324- }
2317+ ConditionalStatements :: BeginEnd ( bes) => write ! ( f, "{}" , bes) ,
2318+ }
2319+ }
2320+ }
2321+
2322+ /// Represents a list of statements enclosed within `BEGIN` and `END` keywords.
2323+ /// Example:
2324+ /// ```sql
2325+ /// BEGIN
2326+ /// SELECT 1;
2327+ /// SELECT 2;
2328+ /// END
2329+ /// ```
2330+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2331+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2332+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
2333+ pub struct BeginEndStatements {
2334+ pub begin_token : AttachedToken ,
2335+ pub statements : Vec < Statement > ,
2336+ pub end_token : AttachedToken ,
2337+ }
2338+
2339+ impl fmt:: Display for BeginEndStatements {
2340+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2341+ let BeginEndStatements {
2342+ begin_token : AttachedToken ( begin_token) ,
2343+ statements,
2344+ end_token : AttachedToken ( end_token) ,
2345+ } = self ;
2346+
2347+ write ! ( f, "{begin_token} " ) ?;
2348+ if !statements. is_empty ( ) {
2349+ format_statement_list ( f, statements) ?;
23252350 }
2351+ write ! ( f, " {end_token}" )
23262352 }
23272353}
23282354
@@ -2446,10 +2472,11 @@ impl fmt::Display for DeclareAssignment {
24462472#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
24472473#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
24482474pub enum DeclareType {
2449- /// Cursor variable type. e.g. [Snowflake] [PostgreSQL]
2475+ /// Cursor variable type. e.g. [Snowflake] [PostgreSQL] [MsSql]
24502476 ///
24512477 /// [Snowflake]: https://docs.snowflake.com/en/developer-guide/snowflake-scripting/cursors#declaring-a-cursor
24522478 /// [PostgreSQL]: https://www.postgresql.org/docs/current/plpgsql-cursors.html
2479+ /// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/language-elements/declare-cursor-transact-sql
24532480 Cursor ,
24542481
24552482 /// Result set variable type. [Snowflake]
@@ -3037,6 +3064,10 @@ pub enum Statement {
30373064 /// CREATE VIEW
30383065 /// ```
30393066 CreateView {
3067+ /// True if this is a `CREATE OR ALTER VIEW` statement
3068+ ///
3069+ /// [MsSql](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-view-transact-sql)
3070+ or_alter : bool ,
30403071 or_replace : bool ,
30413072 materialized : bool ,
30423073 /// View name
@@ -3614,6 +3645,7 @@ pub enum Statement {
36143645 /// 1. [Hive](https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl#LanguageManualDDL-Create/Drop/ReloadFunction)
36153646 /// 2. [PostgreSQL](https://www.postgresql.org/docs/15/sql-createfunction.html)
36163647 /// 3. [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_function_statement)
3648+ /// 4. [MsSql](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql)
36173649 CreateFunction ( CreateFunction ) ,
36183650 /// CREATE TRIGGER
36193651 ///
@@ -4054,6 +4086,18 @@ pub enum Statement {
40544086 arguments : Vec < Expr > ,
40554087 options : Vec < RaisErrorOption > ,
40564088 } ,
4089+ /// ```sql
4090+ /// PRINT msg_str | @local_variable | string_expr
4091+ /// ```
4092+ ///
4093+ /// See: <https://learn.microsoft.com/en-us/sql/t-sql/statements/print-transact-sql>
4094+ Print ( PrintStatement ) ,
4095+ /// ```sql
4096+ /// RETURN [ expression ]
4097+ /// ```
4098+ ///
4099+ /// See [ReturnStatement]
4100+ Return ( ReturnStatement ) ,
40574101}
40584102
40594103#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
@@ -4584,6 +4628,7 @@ impl fmt::Display for Statement {
45844628 Ok ( ( ) )
45854629 }
45864630 Statement :: CreateView {
4631+ or_alter,
45874632 name,
45884633 or_replace,
45894634 columns,
@@ -4600,7 +4645,8 @@ impl fmt::Display for Statement {
46004645 } => {
46014646 write ! (
46024647 f,
4603- "CREATE {or_replace}" ,
4648+ "CREATE {or_alter}{or_replace}" ,
4649+ or_alter = if * or_alter { "OR ALTER " } else { "" } ,
46044650 or_replace = if * or_replace { "OR REPLACE " } else { "" } ,
46054651 ) ?;
46064652 if let Some ( params) = params {
@@ -5745,7 +5791,8 @@ impl fmt::Display for Statement {
57455791 }
57465792 Ok ( ( ) )
57475793 }
5748-
5794+ Statement :: Print ( s) => write ! ( f, "{s}" ) ,
5795+ Statement :: Return ( r) => write ! ( f, "{r}" ) ,
57495796 Statement :: List ( command) => write ! ( f, "LIST {command}" ) ,
57505797 Statement :: Remove ( command) => write ! ( f, "REMOVE {command}" ) ,
57515798 }
@@ -8348,6 +8395,7 @@ impl fmt::Display for FunctionDeterminismSpecifier {
83488395///
83498396/// [BigQuery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_11
83508397/// [PostgreSQL]: https://www.postgresql.org/docs/15/sql-createfunction.html
8398+ /// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql
83518399#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
83528400#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
83538401#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
@@ -8376,6 +8424,22 @@ pub enum CreateFunctionBody {
83768424 ///
83778425 /// [BigQuery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_11
83788426 AsAfterOptions ( Expr ) ,
8427+ /// Function body with statements before the `RETURN` keyword.
8428+ ///
8429+ /// Example:
8430+ /// ```sql
8431+ /// CREATE FUNCTION my_scalar_udf(a INT, b INT)
8432+ /// RETURNS INT
8433+ /// AS
8434+ /// BEGIN
8435+ /// DECLARE c INT;
8436+ /// SET c = a + b;
8437+ /// RETURN c;
8438+ /// END
8439+ /// ```
8440+ ///
8441+ /// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql
8442+ AsBeginEnd ( BeginEndStatements ) ,
83798443 /// Function body expression using the 'RETURN' keyword.
83808444 ///
83818445 /// Example:
@@ -9211,6 +9275,47 @@ pub enum CopyIntoSnowflakeKind {
92119275 Location ,
92129276}
92139277
9278+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
9279+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
9280+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
9281+ pub struct PrintStatement {
9282+ pub message : Box < Expr > ,
9283+ }
9284+
9285+ impl fmt:: Display for PrintStatement {
9286+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
9287+ write ! ( f, "PRINT {}" , self . message)
9288+ }
9289+ }
9290+
9291+ /// Represents a `Return` statement.
9292+ ///
9293+ /// [MsSql triggers](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql)
9294+ /// [MsSql functions](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql)
9295+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
9296+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
9297+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
9298+ pub struct ReturnStatement {
9299+ pub value : Option < ReturnStatementValue > ,
9300+ }
9301+
9302+ impl fmt:: Display for ReturnStatement {
9303+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
9304+ match & self . value {
9305+ Some ( ReturnStatementValue :: Expr ( expr) ) => write ! ( f, "RETURN {}" , expr) ,
9306+ None => write ! ( f, "RETURN" ) ,
9307+ }
9308+ }
9309+ }
9310+
9311+ /// Variants of a `RETURN` statement
9312+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
9313+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
9314+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
9315+ pub enum ReturnStatementValue {
9316+ Expr ( Expr ) ,
9317+ }
9318+
92149319#[ cfg( test) ]
92159320mod tests {
92169321 use super :: * ;
0 commit comments