@@ -318,9 +318,11 @@ impl Dialect for SnowflakeDialect {
318318 }
319319
320320 // `FETCH` can be considered an alias as long as it's not followed by `FIRST`` or `NEXT`
321- // which would give it a different meanings, for example: `SELECT 1 FETCH FIRST 10 ROWS` - not an alias
322- Keyword :: FETCH
323- if parser. peek_keyword ( Keyword :: FIRST ) || parser. peek_keyword ( Keyword :: NEXT ) =>
321+ // which would give it a different meanings, for example:
322+ // `SELECT 1 FETCH FIRST 10 ROWS` - not an alias
323+ // `SELECT 1 FETCH 10` - not an alias
324+ Keyword :: FETCH if parser. peek_one_of_keywords ( & [ Keyword :: FIRST , Keyword :: NEXT ] ) . is_some ( )
325+ || matches ! ( parser. peek_token( ) . token, Token :: Number ( _, _) ) =>
324326 {
325327 false
326328 }
@@ -345,6 +347,86 @@ impl Dialect for SnowflakeDialect {
345347 }
346348 }
347349
350+ fn is_table_alias ( & self , kw : & Keyword , parser : & mut Parser ) -> bool {
351+ match kw {
352+ // The following keywords can be considered an alias as long as
353+ // they are not followed by other tokens that may change their meaning
354+ Keyword :: LIMIT
355+ | Keyword :: RETURNING
356+ | Keyword :: INNER
357+ | Keyword :: USING
358+ | Keyword :: PIVOT
359+ | Keyword :: UNPIVOT
360+ | Keyword :: EXCEPT
361+ | Keyword :: MATCH_RECOGNIZE
362+ | Keyword :: OFFSET
363+ if !matches ! ( parser. peek_token_ref( ) . token, Token :: SemiColon | Token :: EOF ) =>
364+ {
365+ false
366+ }
367+
368+ // `FETCH` can be considered an alias as long as it's not followed by `FIRST`` or `NEXT`
369+ // which would give it a different meanings, for example:
370+ // `SELECT * FROM tbl FETCH FIRST 10 ROWS` - not an alias
371+ // `SELECT * FROM tbl FETCH 10` - not an alias
372+ Keyword :: FETCH
373+ if parser
374+ . peek_one_of_keywords ( & [ Keyword :: FIRST , Keyword :: NEXT ] )
375+ . is_some ( )
376+ || matches ! ( parser. peek_token( ) . token, Token :: Number ( _, _) ) =>
377+ {
378+ false
379+ }
380+
381+ // All sorts of join-related keywords can be considered aliases unless additional
382+ // keywords change their meaning.
383+ Keyword :: RIGHT | Keyword :: LEFT | Keyword :: SEMI | Keyword :: ANTI
384+ if parser
385+ . peek_one_of_keywords ( & [ Keyword :: JOIN , Keyword :: OUTER ] )
386+ . is_some ( ) =>
387+ {
388+ false
389+ }
390+ Keyword :: GLOBAL if parser. peek_keyword ( Keyword :: FULL ) => false ,
391+
392+ // Reserved keywords by the Snowflake dialect, which seem to be less strictive
393+ // than what is listed in `keywords::RESERVED_FOR_TABLE_ALIAS`. The following
394+ // keywords were tested with the this statement: `SELECT <KW>.* FROM tbl <KW>`.
395+ Keyword :: WITH
396+ | Keyword :: ORDER
397+ | Keyword :: SELECT
398+ | Keyword :: WHERE
399+ | Keyword :: GROUP
400+ | Keyword :: HAVING
401+ | Keyword :: LATERAL
402+ | Keyword :: UNION
403+ | Keyword :: INTERSECT
404+ | Keyword :: MINUS
405+ | Keyword :: ON
406+ | Keyword :: JOIN
407+ | Keyword :: INNER
408+ | Keyword :: CROSS
409+ | Keyword :: FULL
410+ | Keyword :: LEFT
411+ | Keyword :: RIGHT
412+ | Keyword :: NATURAL
413+ | Keyword :: USING
414+ | Keyword :: ASOF
415+ | Keyword :: MATCH_CONDITION
416+ | Keyword :: SET
417+ | Keyword :: QUALIFY
418+ | Keyword :: FOR
419+ | Keyword :: START
420+ | Keyword :: CONNECT
421+ | Keyword :: SAMPLE
422+ | Keyword :: TABLESAMPLE
423+ | Keyword :: FROM => false ,
424+
425+ // Any other word is considered an alias
426+ _ => true ,
427+ }
428+ }
429+
348430 /// See: <https://docs.snowflake.com/en/sql-reference/constructs/at-before>
349431 fn supports_timestamp_versioning ( & self ) -> bool {
350432 true
@@ -384,6 +466,10 @@ impl Dialect for SnowflakeDialect {
384466 fn supports_select_expr_star ( & self ) -> bool {
385467 true
386468 }
469+
470+ fn supports_select_wildcard_exclude ( & self ) -> bool {
471+ true
472+ }
387473}
388474
389475fn parse_file_staging_command ( kw : Keyword , parser : & mut Parser ) -> Result < Statement , ParserError > {
0 commit comments