mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-31 19:27:21 +00:00
make parse_expr_with_alias
public (#1444)
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
parent
8a534c0e27
commit
08fc6d3813
1 changed files with 24 additions and 1 deletions
|
@ -10377,8 +10377,31 @@ impl<'a> Parser<'a> {
|
|||
|
||||
Ok(ExprWithAlias { expr, alias })
|
||||
}
|
||||
/// Parses an expression with an optional alias
|
||||
|
||||
fn parse_expr_with_alias(&mut self) -> Result<ExprWithAlias, ParserError> {
|
||||
/// Examples:
|
||||
|
||||
/// ```sql
|
||||
/// SUM(price) AS total_price
|
||||
/// ```
|
||||
|
||||
/// ```sql
|
||||
/// SUM(price)
|
||||
/// ```
|
||||
///
|
||||
/// Example
|
||||
/// ```
|
||||
/// # use sqlparser::parser::{Parser, ParserError};
|
||||
/// # use sqlparser::dialect::GenericDialect;
|
||||
/// # fn main() ->Result<(), ParserError> {
|
||||
/// let sql = r#"SUM("a") as "b""#;
|
||||
/// let mut parser = Parser::new(&GenericDialect).try_with_sql(sql)?;
|
||||
/// let expr_with_alias = parser.parse_expr_with_alias()?;
|
||||
/// assert_eq!(Some("b".to_string()), expr_with_alias.alias.map(|x|x.value));
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
|
||||
pub fn parse_expr_with_alias(&mut self) -> Result<ExprWithAlias, ParserError> {
|
||||
let expr = self.parse_expr()?;
|
||||
let alias = if self.parse_keyword(Keyword::AS) {
|
||||
Some(self.parse_identifier(false)?)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue