@@ -699,7 +699,7 @@ pub enum Expr {
699699 IsNotTrue ( Box < Expr > ) ,
700700 /// `IS NULL` operator
701701 IsNull ( Box < Expr > ) ,
702- /// `IS NOT NULL` operator
702+ /// `IS NOT NULL` operatoDeleter
703703 IsNotNull ( Box < Expr > ) ,
704704 /// `IS UNKNOWN` operator
705705 IsUnknown ( Box < Expr > ) ,
@@ -2678,120 +2678,120 @@ pub enum Set {
26782678 ///
26792679 /// Note: this is a PostgreSQL-specific statements
26802680 /// `SET TIME ZONE <value>` is an alias for `SET timezone TO <value>` in PostgreSQL
2681- /// However, we allow it for all dialects.
2682- SetTimeZone { local : bool , value : Expr } ,
2681+ /// Convenience function, instead of writing `Statement::Set(Set::Set...{...})`
2682+ impl From <Set > for Statement {
2683+ fn from( set : Set ) -> Self {
2684+ Statement : : Set ( set)
2685+ }
2686+ }
2687+
2688+ /// A top-level statement (SELECT, INSERT, CREATE, etc.)
2689+ #[ allow( clippy:: large_enum_variant) ]
2690+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2691+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2692+ #[ cfg_attr(
2693+ feature = "visitor" ,
2694+ derive( Visit , VisitMut ) ,
2695+ visit( with = "visit_statement" )
2696+ ) ]
2697+ pub enum Statement {
26832698 /// ```sql
2684- /// SET NAMES 'charset_name' [COLLATE 'collation_name']
2699+ /// ANALYZE
26852700 /// ```
2686- SetNames {
2687- charset_name : Ident ,
2688- collation_name : Option < String > ,
2701+ /// Analyze (Hive)
2702+ Analyze {
2703+ #[ cfg_attr( feature = "visitor" , visit( with = "visit_relation" ) ) ]
2704+ table_name : ObjectName ,
2705+ partitions : Option < Vec < Expr > > ,
2706+ for_columns : bool ,
2707+ columns : Vec < Ident > ,
2708+ cache_metadata : bool ,
2709+ noscan : bool ,
2710+ compute_statistics : bool ,
2711+ has_table_keyword : bool ,
26892712 } ,
2713+ Set ( Set ) ,
26902714 /// ```sql
2691- /// SET NAMES DEFAULT
2715+ /// TRUNCATE
26922716 /// ```
2693- ///
2694- /// Note: this is a MySQL-specific statement.
2695- SetNamesDefault { } ,
2717+ /// Truncate (Hive)
2718+ Truncate {
2719+ table_names : Vec < TruncateTableTarget > ,
2720+ partitions : Option < Vec < Expr > > ,
2721+ /// TABLE - optional keyword;
2722+ table : bool ,
2723+ /// Postgres-specific option
2724+ /// [ TRUNCATE TABLE ONLY ]
2725+ only : bool ,
2726+ /// Postgres-specific option
2727+ /// [ RESTART IDENTITY | CONTINUE IDENTITY ]
2728+ identity : Option < TruncateIdentityOption > ,
2729+ /// Postgres-specific option
2730+ /// [ CASCADE | RESTRICT ]
2731+ cascade : Option < CascadeOption > ,
2732+ /// ClickHouse-specific option
2733+ /// [ ON CLUSTER cluster_name ]
2734+ ///
2735+ /// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/truncate/)
2736+ on_cluster : Option < Ident > ,
2737+ } ,
26962738 /// ```sql
2697- /// SET TRANSACTION ...
2739+ /// MSCK
26982740 /// ```
2699- SetTransaction {
2700- modes : Vec < TransactionMode > ,
2701- snapshot : Option < Value > ,
2702- session : bool ,
2741+ /// Msck (Hive)
2742+ Msck {
2743+ #[ cfg_attr( feature = "visitor" , visit( with = "visit_relation" ) ) ]
2744+ table_name : ObjectName ,
2745+ repair : bool ,
2746+ partition_action : Option < AddDropSync > ,
27032747 } ,
2704- }
2705-
2706- impl Display for Set {
2707- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2708- match self {
2709- Self :: ParenthesizedAssignments { variables, values } => write ! (
2710- f,
2711- "SET ({}) = ({})" ,
2712- display_comma_separated( variables) ,
2713- display_comma_separated( values)
2714- ) ,
2715- Self :: MultipleAssignments { assignments } => {
2716- write ! ( f, "SET {}" , display_comma_separated( assignments) )
2717- }
2718- Self :: SetRole {
2719- context_modifier,
2720- role_name,
2721- } => {
2722- let role_name = role_name. clone ( ) . unwrap_or_else ( || Ident :: new ( "NONE" ) ) ;
2723- write ! (
2724- f,
2725- "SET {modifier}ROLE {role_name}" ,
2726- modifier = context_modifier
2727- . map( |m| format!( "{}" , m) )
2728- . unwrap_or_default( )
2729- )
2730- }
2731- Self :: SetSessionParam ( kind) => write ! ( f, "SET {kind}" ) ,
2732- Self :: SetTransaction {
2733- modes,
2734- snapshot,
2735- session,
2736- } => {
2737- if * session {
2738- write ! ( f, "SET SESSION CHARACTERISTICS AS TRANSACTION" ) ?;
2739- } else {
2740- write ! ( f, "SET TRANSACTION" ) ?;
2741- }
2742- if !modes. is_empty ( ) {
2743- write ! ( f, " {}" , display_comma_separated( modes) ) ?;
2744- }
2745- if let Some ( snapshot_id) = snapshot {
2746- write ! ( f, " SNAPSHOT {snapshot_id}" ) ?;
2747- }
2748- Ok ( ( ) )
2749- }
2750- Self :: SetTimeZone { local, value } => {
2751- f. write_str ( "SET " ) ?;
2752- if * local {
2753- f. write_str ( "LOCAL " ) ?;
2754- }
2755- write ! ( f, "TIME ZONE {value}" )
2756- }
2757- Self :: SetNames {
2758- charset_name,
2759- collation_name,
2760- } => {
2761- write ! ( f, "SET NAMES {}" , charset_name) ?;
2762-
2763- if let Some ( collation) = collation_name {
2764- f. write_str ( " COLLATE " ) ?;
2765- f. write_str ( collation) ?;
2766- } ;
2767-
2768- Ok ( ( ) )
2769- }
2770- Self :: SetNamesDefault { } => {
2771- f. write_str ( "SET NAMES DEFAULT" ) ?;
2772-
2773- Ok ( ( ) )
2774- }
2775- Set :: SingleAssignment {
2776- scope,
2777- hivevar,
2778- variable,
2779- values,
2780- } => {
2781- write ! (
2782- f,
2783- "SET {}{}{} = {}" ,
2784- scope. map( |s| format!( "{}" , s) ) . unwrap_or_default( ) ,
2785- if * hivevar { "HIVEVAR:" } else { "" } ,
2786- variable,
2787- display_comma_separated( values)
2788- )
2789- }
2790- }
2791- }
2792- }
2793-
2794- /// Convert a `Set` into a `Statement`.
2748+ /// ```sql
2749+ /// SELECT
2750+ /// ```
2751+ Query ( Box < Query > ) ,
2752+ /// ```sql
2753+ /// INSERT
2754+ /// ```
2755+ Insert ( Insert ) ,
2756+ /// ```sql
2757+ /// INSTALL
2758+ /// ```
2759+ Install {
2760+ /// Only for DuckDB
2761+ extension_name : Ident ,
2762+ } ,
2763+ /// ```sql
2764+ /// LOAD
2765+ /// ```
2766+ Load {
2767+ /// Only for DuckDB
2768+ extension_name : Ident ,
2769+ } ,
2770+ // TODO: Support ROW FORMAT
2771+ Directory {
2772+ overwrite : bool ,
2773+ local : bool ,
2774+ path : String ,
2775+ file_format : Option < FileFormat > ,
2776+ source : Box < Query > ,
2777+ } ,
2778+ /// A `CASE` statement.
2779+ Case ( CaseStatement ) ,
2780+ /// An `IF` statement.
2781+ If ( IfStatement ) ,
2782+ /// A `RAISE` statement.
2783+ Raise ( RaiseStatement ) ,
2784+ /// ```sql
2785+ /// CALL <function>
2786+ /// ```
2787+ Call ( Function ) ,
2788+ /// ```sql
2789+ /// COPY [TO | FROM] ...
2790+ /// ```
2791+ Copy {
2792+ /// The source of 'COPY TO', or the target of 'COPY FROM'
2793+ source : CopySource ,
2794+ /// If true, is a 'COPY TO' statement. If false is a 'COPY FROM'
27952795/// Convenience function, instead of writing `Statement::Set(Set::Set...{...})`
27962796 impl From <Set > for Statement {
27972797 fn from( set : Set ) -> Self {
@@ -3817,6 +3817,7 @@ pub enum Statement {
38173817 /// ```
38183818 /// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/merge)
38193819 /// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement)
3820+ /// [MSSQL](https://learn.microsoft.com/en-us/sql/t-sql/statements/merge-transact-sql)
38203821 Merge {
38213822 /// optional INTO keyword
38223823 into : bool ,
@@ -3828,7 +3829,7 @@ pub enum Statement {
38283829 on : Box < Expr > ,
38293830 /// Specifies the actions to perform when values match or do not match.
38303831 clauses : Vec < MergeClause > ,
3831-
3832+ /// Specifies the ouptu clause, to save changed values
38323833 output : Option < Output > ,
38333834 } ,
38343835 /// ```sql
0 commit comments