Skip to content

Commit 08fc6d3

Browse files
Eason0729alambiffyio
authored
make parse_expr_with_alias public (#1444)
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
1 parent 8a534c0 commit 08fc6d3

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/parser/mod.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10377,8 +10377,31 @@ impl<'a> Parser<'a> {
1037710377

1037810378
Ok(ExprWithAlias { expr, alias })
1037910379
}
10380+
/// Parses an expression with an optional alias
1038010381
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> {
1038210405
let expr = self.parse_expr()?;
1038310406
let alias = if self.parse_keyword(Keyword::AS) {
1038410407
Some(self.parse_identifier(false)?)

0 commit comments

Comments
 (0)