Skip to content

Commit cdf983c

Browse files
committed
impl Spanned for MERGE statements
1 parent 1198c1a commit cdf983c

File tree

5 files changed

+398
-34
lines changed

5 files changed

+398
-34
lines changed

src/ast/mod.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4048,6 +4048,8 @@ pub enum Statement {
40484048
/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement)
40494049
/// [MSSQL](https://learn.microsoft.com/en-us/sql/t-sql/statements/merge-transact-sql?view=sql-server-ver16)
40504050
Merge {
4051+
/// The `MERGE` token that starts the statement.
4052+
merge_token: AttachedToken,
40514053
/// optional INTO keyword
40524054
into: bool,
40534055
/// Specifies the table to merge
@@ -4072,7 +4074,6 @@ pub enum Statement {
40724074
/// Table flag
40734075
table_flag: Option<ObjectName>,
40744076
/// Table name
4075-
40764077
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
40774078
table_name: ObjectName,
40784079
has_as: bool,
@@ -5467,6 +5468,7 @@ impl fmt::Display for Statement {
54675468
write!(f, "RELEASE SAVEPOINT {name}")
54685469
}
54695470
Statement::Merge {
5471+
merge_token: _,
54705472
into,
54715473
table,
54725474
source,
@@ -8599,6 +8601,8 @@ impl Display for MergeInsertKind {
85998601
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
86008602
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
86018603
pub struct MergeInsertExpr {
8604+
/// The `INSERT` token that starts the sub-expression.
8605+
pub insert_token: AttachedToken,
86028606
/// Columns (if any) specified by the insert.
86038607
///
86048608
/// Example:
@@ -8607,6 +8611,8 @@ pub struct MergeInsertExpr {
86078611
/// INSERT (product, quantity) ROW
86088612
/// ```
86098613
pub columns: Vec<Ident>,
8614+
/// The token, `[VALUES | ROW]` starting `kind`.
8615+
pub kind_token: AttachedToken,
86108616
/// The insert type used by the statement.
86118617
pub kind: MergeInsertKind,
86128618
}
@@ -8646,9 +8652,16 @@ pub enum MergeAction {
86468652
/// ```sql
86478653
/// UPDATE SET quantity = T.quantity + S.quantity
86488654
/// ```
8649-
Update { assignments: Vec<Assignment> },
8655+
Update {
8656+
/// The `UPDATE` token that starts the sub-expression.
8657+
update_token: AttachedToken,
8658+
assignments: Vec<Assignment>,
8659+
},
86508660
/// A plain `DELETE` clause
8651-
Delete,
8661+
Delete {
8662+
/// The `DELETE` token that starts the sub-expression.
8663+
delete_token: AttachedToken,
8664+
},
86528665
}
86538666

86548667
impl Display for MergeAction {
@@ -8657,10 +8670,10 @@ impl Display for MergeAction {
86578670
MergeAction::Insert(insert) => {
86588671
write!(f, "INSERT {insert}")
86598672
}
8660-
MergeAction::Update { assignments } => {
8673+
MergeAction::Update { assignments, .. } => {
86618674
write!(f, "UPDATE SET {}", display_comma_separated(assignments))
86628675
}
8663-
MergeAction::Delete => {
8676+
MergeAction::Delete { .. } => {
86648677
write!(f, "DELETE")
86658678
}
86668679
}
@@ -8679,6 +8692,8 @@ impl Display for MergeAction {
86798692
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
86808693
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
86818694
pub struct MergeClause {
8695+
/// The `WHEN` token that starts the sub-expression.
8696+
pub when_token: AttachedToken,
86828697
pub clause_kind: MergeClauseKind,
86838698
pub predicate: Option<Expr>,
86848699
pub action: MergeAction,
@@ -8687,6 +8702,7 @@ pub struct MergeClause {
86878702
impl Display for MergeClause {
86888703
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
86898704
let MergeClause {
8705+
when_token: _,
86908706
clause_kind,
86918707
predicate,
86928708
action,
@@ -8710,10 +8726,12 @@ impl Display for MergeClause {
87108726
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
87118727
pub enum OutputClause {
87128728
Output {
8729+
output_token: AttachedToken,
87138730
select_items: Vec<SelectItem>,
87148731
into_table: Option<SelectInto>,
87158732
},
87168733
Returning {
8734+
returning_token: AttachedToken,
87178735
select_items: Vec<SelectItem>,
87188736
},
87198737
}
@@ -8722,6 +8740,7 @@ impl fmt::Display for OutputClause {
87228740
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
87238741
match self {
87248742
OutputClause::Output {
8743+
output_token: _,
87258744
select_items,
87268745
into_table,
87278746
} => {
@@ -8733,7 +8752,10 @@ impl fmt::Display for OutputClause {
87338752
}
87348753
Ok(())
87358754
}
8736-
OutputClause::Returning { select_items } => {
8755+
OutputClause::Returning {
8756+
returning_token: _,
8757+
select_items,
8758+
} => {
87378759
f.write_str("RETURNING ")?;
87388760
display_comma_separated(select_items).fmt(f)
87398761
}

0 commit comments

Comments
 (0)