File tree Expand file tree Collapse file tree 6 files changed +277
-191
lines changed Expand file tree Collapse file tree 6 files changed +277
-191
lines changed Original file line number Diff line number Diff line change @@ -681,6 +681,12 @@ pub trait Dialect: Debug + Any {
681681 fn supports_partiql ( & self ) -> bool {
682682 false
683683 }
684+
685+ /// Returns true if the specified keyword is reserved and cannot be
686+ /// used as an identifier without special handling like quoting.
687+ fn is_reserved_for_identifier ( & self , kw : Keyword ) -> bool {
688+ keywords:: RESERVED_FOR_IDENTIFIER . contains ( & kw)
689+ }
684690}
685691
686692/// This represents the operators for which precedence must be defined
Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ use alloc::vec::Vec;
3838#[ cfg( not( feature = "std" ) ) ]
3939use alloc:: { format, vec} ;
4040
41+ use super :: keywords:: RESERVED_FOR_IDENTIFIER ;
42+
4143/// A [`Dialect`] for [Snowflake](https://www.snowflake.com/)
4244#[ derive( Debug , Default ) ]
4345pub struct SnowflakeDialect ;
@@ -214,6 +216,16 @@ impl Dialect for SnowflakeDialect {
214216 fn supports_show_like_before_in ( & self ) -> bool {
215217 true
216218 }
219+
220+ fn is_reserved_for_identifier ( & self , kw : Keyword ) -> bool {
221+ // Unreserve some keywords that Snowflake accepts as identifiers
222+ // See: https://docs.snowflake.com/en/sql-reference/reserved-keywords
223+ if matches ! ( kw, Keyword :: INTERVAL ) {
224+ false
225+ } else {
226+ RESERVED_FOR_IDENTIFIER . contains ( & kw)
227+ }
228+ }
217229}
218230
219231/// Parse snowflake create table statement.
Original file line number Diff line number Diff line change @@ -948,3 +948,13 @@ pub const RESERVED_FOR_COLUMN_ALIAS: &[Keyword] = &[
948948 Keyword :: INTO ,
949949 Keyword :: END ,
950950] ;
951+
952+ /// Global list of reserved keywords that cannot be parsed as identifiers
953+ /// without special handling like quoting. Parser should call `Dialect::is_reserved_for_identifier`
954+ /// to allow for each dialect to customize the list.
955+ pub const RESERVED_FOR_IDENTIFIER : & [ Keyword ] = & [
956+ Keyword :: EXISTS ,
957+ Keyword :: INTERVAL ,
958+ Keyword :: STRUCT ,
959+ Keyword :: TRIM ,
960+ ] ;
You can’t perform that action at this time.
0 commit comments