yoavcloud commented on code in PR #1467:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1467#discussion_r1803740062


##########
src/parser/mod.rs:
##########
@@ -11173,12 +11173,36 @@ impl<'a> Parser<'a> {
                     self.peek_token().location
                 )
             }
-            expr => self
-                .parse_optional_alias(keywords::RESERVED_FOR_COLUMN_ALIAS)
-                .map(|alias| match alias {
-                    Some(alias) => SelectItem::ExprWithAlias { expr, alias },
-                    None => SelectItem::UnnamedExpr(expr),
-                }),
+            expr => {
+                // Parse a [`SelectItem`] based on an [MsSql] syntax that uses 
the equal sign
+                // to denote an alias, for example: SELECT col_alias = col 
FROM tbl
+                // [MsSql]: 
https://learn.microsoft.com/en-us/sql/t-sql/queries/select-examples-transact-sql?view=sql-server-ver16#b-use-select-with-column-headings-and-calculations
+                let expr = if self.dialect.supports_eq_alias_assigment() {
+                    if let Expr::BinaryOp {
+                        ref left,
+                        op: BinaryOperator::Eq,
+                        ref right,
+                    } = expr
+                    {
+                        if let Expr::Identifier(alias) = left.as_ref() {
+                            return Ok(SelectItem::ExprWithAlias {
+                                expr: *right.clone(),
+                                alias: alias.clone(),
+                            });
+                        }
+                    }
+                    expr
+                } else {
+                    expr
+                };
+
+                // Parse the common AS keyword for aliasing a column
+                self.parse_optional_alias(keywords::RESERVED_FOR_COLUMN_ALIAS)
+                    .map(|alias| match alias {
+                        Some(alias) => SelectItem::ExprWithAlias { expr, alias 
},
+                        None => SelectItem::UnnamedExpr(expr),
+                    })

Review Comment:
   Impressive! Adopted in the next commit



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to