File tree 4 files changed +50
-0
lines changed
4 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -561,6 +561,17 @@ pub trait Dialect: Debug + Any {
561
561
fn supports_asc_desc_in_column_definition ( & self ) -> bool {
562
562
false
563
563
}
564
+
565
+ /// Returns true if this dialect supports treating the equals operator `=` within a `SelectItem`
566
+ /// as an alias assignment operator, rather than a boolean expression.
567
+ /// For example: the following statements are equivalent for such a dialect:
568
+ /// ```sql
569
+ /// SELECT col_alias = col FROM tbl;
570
+ /// SELECT col_alias AS col FROM tbl;
571
+ /// ```
572
+ fn supports_eq_alias_assigment ( & self ) -> bool {
573
+ false
574
+ }
564
575
}
565
576
566
577
/// This represents the operators for which precedence must be defined
Original file line number Diff line number Diff line change @@ -49,4 +49,8 @@ impl Dialect for MsSqlDialect {
49
49
fn supports_connect_by ( & self ) -> bool {
50
50
true
51
51
}
52
+
53
+ fn supports_eq_alias_assigment ( & self ) -> bool {
54
+ true
55
+ }
52
56
}
Original file line number Diff line number Diff line change @@ -11181,6 +11181,24 @@ impl<'a> Parser<'a> {
11181
11181
self . peek_token( ) . location
11182
11182
)
11183
11183
}
11184
+ Expr :: BinaryOp {
11185
+ left,
11186
+ op : BinaryOperator :: Eq ,
11187
+ right,
11188
+ } if self . dialect . supports_eq_alias_assigment ( )
11189
+ && matches ! ( left. as_ref( ) , Expr :: Identifier ( _) ) =>
11190
+ {
11191
+ let Expr :: Identifier ( alias) = * left else {
11192
+ return parser_err ! (
11193
+ "BUG: expected identifier expression as alias" ,
11194
+ self . peek_token( ) . location
11195
+ ) ;
11196
+ } ;
11197
+ Ok ( SelectItem :: ExprWithAlias {
11198
+ expr : * right,
11199
+ alias,
11200
+ } )
11201
+ }
11184
11202
expr => self
11185
11203
. parse_optional_alias ( keywords:: RESERVED_FOR_COLUMN_ALIAS )
11186
11204
. map ( |alias| match alias {
Original file line number Diff line number Diff line change @@ -11432,3 +11432,20 @@ fn test_any_some_all_comparison() {
11432
11432
verified_stmt ( "SELECT c1 FROM tbl WHERE c1 <> SOME(SELECT c2 FROM tbl)" ) ;
11433
11433
verified_stmt ( "SELECT 1 = ANY(WITH x AS (SELECT 1) SELECT * FROM x)" ) ;
11434
11434
}
11435
+
11436
+ #[ test]
11437
+ fn test_alias_equal_expr ( ) {
11438
+ let dialects = all_dialects_where ( |d| d. supports_eq_alias_assigment ( ) ) ;
11439
+ let sql = r#"SELECT some_alias = some_column FROM some_table"# ;
11440
+ let expected = r#"SELECT some_column AS some_alias FROM some_table"# ;
11441
+ let _ = dialects. one_statement_parses_to ( sql, expected) ;
11442
+
11443
+ let sql = r#"SELECT some_alias = (a*b) FROM some_table"# ;
11444
+ let expected = r#"SELECT (a * b) AS some_alias FROM some_table"# ;
11445
+ let _ = dialects. one_statement_parses_to ( sql, expected) ;
11446
+
11447
+ let dialects = all_dialects_where ( |d| !d. supports_eq_alias_assigment ( ) ) ;
11448
+ let sql = r#"SELECT x = (a * b) FROM some_table"# ;
11449
+ let expected = r#"SELECT x = (a * b) FROM some_table"# ;
11450
+ let _ = dialects. one_statement_parses_to ( sql, expected) ;
11451
+ }
You can’t perform that action at this time.
0 commit comments