@@ -44,7 +44,9 @@ pub use self::value::{
44
44
escape_quoted_string, DateTimeField , DollarQuotedString , TrimWhereField , Value ,
45
45
} ;
46
46
47
- use crate :: ast:: helpers:: stmt_data_loading:: { DataLoadingOptions , StageParamsObject } ;
47
+ use crate :: ast:: helpers:: stmt_data_loading:: {
48
+ DataLoadingOptions , StageLoadSelectItem , StageParamsObject ,
49
+ } ;
48
50
#[ cfg( feature = "visitor" ) ]
49
51
pub use visitor:: * ;
50
52
@@ -1187,6 +1189,26 @@ pub enum Statement {
1187
1189
/// VALUES a vector of values to be copied
1188
1190
values : Vec < Option < String > > ,
1189
1191
} ,
1192
+ /// ```sql
1193
+ /// COPY INTO
1194
+ /// ```
1195
+ /// See <https://docs.snowflake.com/en/sql-reference/sql/copy-into-table>
1196
+ /// Copy Into syntax available for Snowflake is different than the one implemented in
1197
+ /// Postgres. Although they share common prefix, it is reasonable to implement them
1198
+ /// in different enums. This can be refactored later once custom dialects
1199
+ /// are allowed to have custom Statements.
1200
+ CopyIntoSnowflake {
1201
+ into : ObjectName ,
1202
+ from_stage : ObjectName ,
1203
+ from_stage_alias : Option < Ident > ,
1204
+ stage_params : StageParamsObject ,
1205
+ from_transformations : Option < Vec < StageLoadSelectItem > > ,
1206
+ files : Option < Vec < String > > ,
1207
+ pattern : Option < String > ,
1208
+ file_format : DataLoadingOptions ,
1209
+ copy_options : DataLoadingOptions ,
1210
+ validation_mode : Option < String > ,
1211
+ } ,
1190
1212
/// Close - closes the portal underlying an open cursor.
1191
1213
Close {
1192
1214
/// Cursor name
@@ -2795,6 +2817,64 @@ impl fmt::Display for Statement {
2795
2817
}
2796
2818
Ok ( ( ) )
2797
2819
}
2820
+ Statement :: CopyIntoSnowflake {
2821
+ into,
2822
+ from_stage,
2823
+ from_stage_alias,
2824
+ stage_params,
2825
+ from_transformations,
2826
+ files,
2827
+ pattern,
2828
+ file_format,
2829
+ copy_options,
2830
+ validation_mode,
2831
+ } => {
2832
+ write ! ( f, "COPY INTO {}" , into) ?;
2833
+ if from_transformations. is_none ( ) {
2834
+ // Standard data load
2835
+ write ! ( f, " FROM {}{}" , from_stage, stage_params) ?;
2836
+ if from_stage_alias. as_ref ( ) . is_some ( ) {
2837
+ write ! ( f, " AS {}" , from_stage_alias. as_ref( ) . unwrap( ) ) ?;
2838
+ }
2839
+ } else {
2840
+ // Data load with transformation
2841
+ write ! (
2842
+ f,
2843
+ " FROM (SELECT {} FROM {}{}" ,
2844
+ display_separated( from_transformations. as_ref( ) . unwrap( ) , ", " ) ,
2845
+ from_stage,
2846
+ stage_params,
2847
+ ) ?;
2848
+ if from_stage_alias. as_ref ( ) . is_some ( ) {
2849
+ write ! ( f, " AS {}" , from_stage_alias. as_ref( ) . unwrap( ) ) ?;
2850
+ }
2851
+ write ! ( f, ")" ) ?;
2852
+ }
2853
+ if files. is_some ( ) {
2854
+ write ! (
2855
+ f,
2856
+ " FILES = ('{}')" ,
2857
+ display_separated( files. as_ref( ) . unwrap( ) , "', '" )
2858
+ ) ?;
2859
+ }
2860
+ if pattern. is_some ( ) {
2861
+ write ! ( f, " PATTERN = '{}'" , pattern. as_ref( ) . unwrap( ) ) ?;
2862
+ }
2863
+ if !file_format. options . is_empty ( ) {
2864
+ write ! ( f, " FILE_FORMAT=({})" , file_format) ?;
2865
+ }
2866
+ if !copy_options. options . is_empty ( ) {
2867
+ write ! ( f, " COPY_OPTIONS=({})" , copy_options) ?;
2868
+ }
2869
+ if validation_mode. is_some ( ) {
2870
+ write ! (
2871
+ f,
2872
+ " VALIDATION_MODE = {}" ,
2873
+ validation_mode. as_ref( ) . unwrap( )
2874
+ ) ?;
2875
+ }
2876
+ Ok ( ( ) )
2877
+ }
2798
2878
}
2799
2879
}
2800
2880
}
0 commit comments