File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -10377,8 +10377,31 @@ impl<'a> Parser<'a> {
10377
10377
10378
10378
Ok ( ExprWithAlias { expr, alias } )
10379
10379
}
10380
+ /// Parses an expression with an optional alias
10380
10381
10381
- fn parse_expr_with_alias ( & mut self ) -> Result < ExprWithAlias , ParserError > {
10382
+ /// Examples:
10383
+
10384
+ /// ```sql
10385
+ /// SUM(price) AS total_price
10386
+ /// ```
10387
+
10388
+ /// ```sql
10389
+ /// SUM(price)
10390
+ /// ```
10391
+ ///
10392
+ /// Example
10393
+ /// ```
10394
+ /// # use sqlparser::parser::{Parser, ParserError};
10395
+ /// # use sqlparser::dialect::GenericDialect;
10396
+ /// # fn main() ->Result<(), ParserError> {
10397
+ /// let sql = r#"SUM("a") as "b""#;
10398
+ /// let mut parser = Parser::new(&GenericDialect).try_with_sql(sql)?;
10399
+ /// let expr_with_alias = parser.parse_expr_with_alias()?;
10400
+ /// assert_eq!(Some("b".to_string()), expr_with_alias.alias.map(|x|x.value));
10401
+ /// # Ok(())
10402
+ /// # }
10403
+
10404
+ pub fn parse_expr_with_alias ( & mut self ) -> Result < ExprWithAlias , ParserError > {
10382
10405
let expr = self . parse_expr ( ) ?;
10383
10406
let alias = if self . parse_keyword ( Keyword :: AS ) {
10384
10407
Some ( self . parse_identifier ( false ) ?)
You can’t perform that action at this time.
0 commit comments