File tree Expand file tree Collapse file tree 5 files changed +66
-0
lines changed
Expand file tree Collapse file tree 5 files changed +66
-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]
3939 "--ansi" => Box :: new ( AnsiDialect { } ) ,
4040 "--postgres" => Box :: new ( PostgreSqlDialect { } ) ,
4141 "--ms" => Box :: new ( MsSqlDialect { } ) ,
42+ "--snowflake" => Box :: new ( SnowflakeDialect { } ) ,
4243 "--generic" | "" => Box :: new ( GenericDialect { } ) ,
4344 s => panic ! ( "Unexpected parameter: {}" , s) ,
4445 } ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ pub mod keywords;
1616mod mssql;
1717mod mysql;
1818mod postgresql;
19+ mod snowflake;
1920mod sqlite;
2021
2122use std:: any:: { Any , TypeId } ;
@@ -26,6 +27,7 @@ pub use self::generic::GenericDialect;
2627pub use self :: mssql:: MsSqlDialect ;
2728pub use self :: mysql:: MySqlDialect ;
2829pub use self :: postgresql:: PostgreSqlDialect ;
30+ pub use self :: snowflake:: SnowflakeDialect ;
2931pub use self :: sqlite:: SQLiteDialect ;
3032
3133/// `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 @@ -119,6 +119,7 @@ pub fn all_dialects() -> TestedDialects {
119119 Box :: new( PostgreSqlDialect { } ) ,
120120 Box :: new( MsSqlDialect { } ) ,
121121 Box :: new( AnsiDialect { } ) ,
122+ Box :: new( SnowflakeDialect { } ) ,
122123 ] ,
123124 }
124125}
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