File tree 4 files changed +65
-0
lines changed
4 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ $ cargo run --feature json_example --example cli FILENAME.sql [--dialectname]
39
39
"--ansi" => Box :: new ( AnsiDialect { } ) ,
40
40
"--postgres" => Box :: new ( PostgreSqlDialect { } ) ,
41
41
"--ms" => Box :: new ( MsSqlDialect { } ) ,
42
+ "--snowflake" => Box :: new ( SnowflakeDialect { } ) ,
42
43
"--generic" | "" => Box :: new ( GenericDialect { } ) ,
43
44
s => panic ! ( "Unexpected parameter: {}" , s) ,
44
45
} ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ pub mod keywords;
16
16
mod mssql;
17
17
mod mysql;
18
18
mod postgresql;
19
+ mod snowflake;
19
20
mod sqlite;
20
21
21
22
use std:: any:: { Any , TypeId } ;
@@ -26,6 +27,7 @@ pub use self::generic::GenericDialect;
26
27
pub use self :: mssql:: MsSqlDialect ;
27
28
pub use self :: mysql:: MySqlDialect ;
28
29
pub use self :: postgresql:: PostgreSqlDialect ;
30
+ pub use self :: snowflake:: SnowflakeDialect ;
29
31
pub use self :: sqlite:: SQLiteDialect ;
30
32
31
33
/// `dialect_of!(parser is SQLiteDialect | GenericDialect)` evaluates
Original file line number Diff line number Diff line change
1
+ // Licensed under the Apache License, Version 2.0 (the "License");
2
+ // you may not use this file except in compliance with the License.
3
+ // You may obtain a copy of the License at
4
+ //
5
+ // http://www.apache.org/licenses/LICENSE-2.0
6
+ //
7
+ // Unless required by applicable law or agreed to in writing, software
8
+ // distributed under the License is distributed on an "AS IS" BASIS,
9
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ // See the License for the specific language governing permissions and
11
+ // limitations under the License.
12
+
13
+ use crate :: dialect:: Dialect ;
14
+
15
+ #[ derive( Debug , Default ) ]
16
+ pub struct SnowflakeDialect ;
17
+
18
+ impl Dialect for SnowflakeDialect {
19
+ // see https://docs.snowflake.com/en/sql-reference/identifiers-syntax.html
20
+ fn is_identifier_start ( & self , ch : char ) -> bool {
21
+ ( ch >= 'a' && ch <= 'z' ) || ( ch >= 'A' && ch <= 'Z' ) || ch == '_'
22
+ }
23
+
24
+ fn is_identifier_part ( & self , ch : char ) -> bool {
25
+ ( ch >= 'a' && ch <= 'z' )
26
+ || ( ch >= 'A' && ch <= 'Z' )
27
+ || ( ch >= '0' && ch <= '9' )
28
+ || ch == '$'
29
+ || ch == '_'
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ // Licensed under the Apache License, Version 2.0 (the "License");
2
+ // you may not use this file except in compliance with the License.
3
+ // You may obtain a copy of the License at
4
+ //
5
+ // http://www.apache.org/licenses/LICENSE-2.0
6
+ //
7
+ // Unless required by applicable law or agreed to in writing, software
8
+ // distributed under the License is distributed on an "AS IS" BASIS,
9
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ // See the License for the specific language governing permissions and
11
+ // limitations under the License.
12
+ use sqlparser:: ast:: * ;
13
+ use sqlparser:: dialect:: { GenericDialect , SnowflakeDialect } ;
14
+ use sqlparser:: test_utils:: * ;
15
+
16
+ #[ test]
17
+ fn test_snowflake_create_table ( ) {
18
+ let sql = "CREATE TABLE _my_$table (am00unt number)" ;
19
+ match snowflake_and_generic ( ) . verified_stmt ( sql) {
20
+ Statement :: CreateTable { name, .. } => {
21
+ assert_eq ! ( "_my_$table" , name. to_string( ) ) ;
22
+ }
23
+ _ => unreachable ! ( ) ,
24
+ }
25
+ }
26
+
27
+ fn snowflake_and_generic ( ) -> TestedDialects {
28
+ TestedDialects {
29
+ dialects : vec ! [ Box :: new( SnowflakeDialect { } ) , Box :: new( GenericDialect { } ) ] ,
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments