Skip to content

Commit a50487e

Browse files
committed
redefine ast
1 parent d86b741 commit a50487e

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/ast/query.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl fmt::Display for ExceptSelectItem {
535535
///
536536
/// # Syntax
537537
/// ```plaintext
538-
/// REPLACE <new_expr> AS <col_name>
538+
/// REPLACE <new_expr> [AS] <col_name>
539539
/// ```
540540
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
541541
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -545,15 +545,15 @@ pub enum ReplaceSelectItem {
545545
///
546546
/// # Syntax
547547
/// ```plaintext
548-
/// <col_name> AS <col_alias>
548+
/// <col_name> [AS] <col_alias>
549549
/// ```
550-
Single(Box<SelectItem>),
550+
Single(Box<ReplaceSelectElement>),
551551
/// Multiple column names with aliases inside parenthesis.
552552
/// # Syntax
553553
/// ```plaintext
554-
/// (<col_name> AS <col_alias>, <col_name> AS <col_alias>, ...)
554+
/// (<col_name> [AS] <col_alias>, <col_name> [AS] <col_alias>, ...)
555555
/// ```
556-
Multiple(Vec<Box<SelectItem>>),
556+
Multiple(Vec<Box<ReplaceSelectElement>>),
557557
}
558558

559559
impl fmt::Display for ReplaceSelectItem {
@@ -571,6 +571,27 @@ impl fmt::Display for ReplaceSelectItem {
571571
}
572572
}
573573

574+
/// # Syntax
575+
/// ```plaintext
576+
/// <expr> [AS] <column_name>
577+
/// ```
578+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
579+
pub struct ReplaceSelectElement {
580+
pub expr: Expr,
581+
pub colum_name: Ident,
582+
pub as_keyword: bool,
583+
}
584+
585+
impl fmt::Display for ReplaceSelectElement {
586+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
587+
if self.as_keyword {
588+
write!(f, "{} AS {}", self.expr, self.colum_name)
589+
} else {
590+
write!(f, "{} {}", self.expr, self.colum_name)
591+
}
592+
}
593+
}
594+
574595
impl fmt::Display for SelectItem {
575596
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
576597
match &self {

0 commit comments

Comments
 (0)