@@ -21,14 +21,12 @@ use crate::ast::{
2121 GranteesType , IfStatement , Statement ,
2222} ;
2323use crate :: dialect:: Dialect ;
24- use crate :: keywords:: { self , Keyword } ;
24+ use crate :: keywords:: Keyword ;
2525use crate :: parser:: { Parser , ParserError } ;
2626use crate :: tokenizer:: Token ;
2727#[ cfg( not( feature = "std" ) ) ]
2828use alloc:: { vec, vec:: Vec } ;
2929
30- const RESERVED_FOR_COLUMN_ALIAS : & [ Keyword ] = & [ Keyword :: IF , Keyword :: ELSE ] ;
31-
3230/// A [`Dialect`] for [Microsoft SQL Server](https://www.microsoft.com/en-us/sql-server/)
3331#[ derive( Debug ) ]
3432pub struct MsSqlDialect { }
@@ -128,8 +126,22 @@ impl Dialect for MsSqlDialect {
128126 & [ GranteesType :: Public ]
129127 }
130128
131- fn is_column_alias ( & self , kw : & Keyword , _parser : & mut Parser ) -> bool {
132- !keywords:: RESERVED_FOR_COLUMN_ALIAS . contains ( kw) && !RESERVED_FOR_COLUMN_ALIAS . contains ( kw)
129+ fn is_select_item_alias ( & self , explicit : bool , kw : & Keyword , parser : & mut Parser ) -> bool {
130+ match kw {
131+ // List of keywords that cannot be used as select item aliases in MSSQL
132+ // regardless of whether the alias is explicit or implicit
133+ Keyword :: IF | Keyword :: ELSE => false ,
134+ _ => explicit || self . is_column_alias ( kw, parser) ,
135+ }
136+ }
137+
138+ fn is_table_factor_alias ( & self , explicit : bool , kw : & Keyword , parser : & mut Parser ) -> bool {
139+ match kw {
140+ // List of keywords that cannot be used as table aliases in MSSQL
141+ // regardless of whether the alias is explicit or implicit
142+ Keyword :: IF | Keyword :: ELSE => false ,
143+ _ => explicit || self . is_table_alias ( kw, parser) ,
144+ }
133145 }
134146
135147 fn parse_statement ( & self , parser : & mut Parser ) -> Option < Result < Statement , ParserError > > {
0 commit comments