File tree 4 files changed +54
-0
lines changed
4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -342,6 +342,16 @@ pub trait Dialect: Debug + Any {
342
342
self . supports_trailing_commas ( )
343
343
}
344
344
345
+ /// Returns true if the dialect supports double dot notation for object names
346
+ ///
347
+ /// Example
348
+ /// ```sql
349
+ /// SELECT * FROM db_name..table_name
350
+ /// ```
351
+ fn supports_object_name_double_dot_notation ( & self ) -> bool {
352
+ false
353
+ }
354
+
345
355
/// Dialect-specific infix parser override
346
356
///
347
357
/// This method is called to parse the next infix expression.
Original file line number Diff line number Diff line change @@ -52,6 +52,14 @@ impl Dialect for SnowflakeDialect {
52
52
true
53
53
}
54
54
55
+ // Snowflake supports double-dot notation when the schema name is not specified
56
+ // In this case the default PUBLIC schema is used
57
+ //
58
+ // see https://docs.snowflake.com/en/sql-reference/name-resolution#resolution-when-schema-omitted-double-dot-notation
59
+ fn supports_object_name_double_dot_notation ( & self ) -> bool {
60
+ true
61
+ }
62
+
55
63
fn is_identifier_part ( & self , ch : char ) -> bool {
56
64
ch. is_ascii_lowercase ( )
57
65
|| ch. is_ascii_uppercase ( )
Original file line number Diff line number Diff line change @@ -8349,6 +8349,13 @@ impl<'a> Parser<'a> {
8349
8349
pub fn parse_object_name(&mut self, in_table_clause: bool) -> Result<ObjectName, ParserError> {
8350
8350
let mut idents = vec![];
8351
8351
loop {
8352
+ if self.dialect.supports_object_name_double_dot_notation()
8353
+ && !idents.is_empty()
8354
+ && self.peek_token() == Token::Period
8355
+ {
8356
+ self.next_token();
8357
+ idents.push(Ident::new(""));
8358
+ }
8352
8359
idents.push(self.parse_identifier(in_table_clause)?);
8353
8360
if !self.consume_token(&Token::Period) {
8354
8361
break;
Original file line number Diff line number Diff line change @@ -2846,3 +2846,32 @@ fn test_parse_show_columns_sql() {
2846
2846
snowflake ( ) . verified_stmt ( "SHOW COLUMNS IN TABLE abc" ) ;
2847
2847
snowflake ( ) . verified_stmt ( "SHOW COLUMNS LIKE '%xyz%' IN TABLE abc" ) ;
2848
2848
}
2849
+
2850
+ #[ test]
2851
+ fn test_sf_double_dot_notation ( ) {
2852
+ snowflake ( ) . verified_stmt ( "SELECT * FROM db_name..table_name" ) ;
2853
+ snowflake ( ) . verified_stmt ( "SELECT * FROM x, y..z JOIN a..b as as b ON x.id = b.id" ) ;
2854
+ }
2855
+
2856
+ #[ test]
2857
+ fn test_sf_double_dot_notation_wrong_position ( ) { }
2858
+
2859
+ #[ test]
2860
+ fn test_parse_double_dot_notation_wrong_position ( ) {
2861
+ assert_eq ! (
2862
+ snowflake( )
2863
+ . parse_sql_statements( "SELECT * FROM X.Y.." )
2864
+ . unwrap_err( )
2865
+ . to_string( ) ,
2866
+ "sql parser error: Expected: identifier, found: ."
2867
+ ) ;
2868
+
2869
+ assert_eq ! (
2870
+ // Ensure we don't parse leading token
2871
+ snowflake( )
2872
+ . parse_sql_statements( "SELECT * FROM .X.Y" )
2873
+ . unwrap_err( )
2874
+ . to_string( ) ,
2875
+ "sql parser error: Expected: identifier, found: ."
2876
+ ) ;
2877
+ }
You can’t perform that action at this time.
0 commit comments