Skip to content

Commit 56b8fe6

Browse files
committed
impl Spanned for MERGE statements
1 parent 1114d6a commit 56b8fe6

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
@@ -4064,6 +4064,8 @@ pub enum Statement {
40644064
/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement)
40654065
/// [MSSQL](https://learn.microsoft.com/en-us/sql/t-sql/statements/merge-transact-sql?view=sql-server-ver16)
40664066
Merge {
4067+
/// The `MERGE` token that starts the statement.
4068+
merge_token: AttachedToken,
40674069
/// optional INTO keyword
40684070
into: bool,
40694071
/// Specifies the table to merge
@@ -4088,7 +4090,6 @@ pub enum Statement {
40884090
/// Table flag
40894091
table_flag: Option<ObjectName>,
40904092
/// Table name
4091-
40924093
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
40934094
table_name: ObjectName,
40944095
has_as: bool,
@@ -5488,6 +5489,7 @@ impl fmt::Display for Statement {
54885489
write!(f, "RELEASE SAVEPOINT {name}")
54895490
}
54905491
Statement::Merge {
5492+
merge_token: _,
54915493
into,
54925494
table,
54935495
source,
@@ -8620,6 +8622,8 @@ impl Display for MergeInsertKind {
86208622
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
86218623
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
86228624
pub struct MergeInsertExpr {
8625+
/// The `INSERT` token that starts the sub-expression.
8626+
pub insert_token: AttachedToken,
86238627
/// Columns (if any) specified by the insert.
86248628
///
86258629
/// Example:
@@ -8628,6 +8632,8 @@ pub struct MergeInsertExpr {
86288632
/// INSERT (product, quantity) ROW
86298633
/// ```
86308634
pub columns: Vec<Ident>,
8635+
/// The token, `[VALUES | ROW]` starting `kind`.
8636+
pub kind_token: AttachedToken,
86318637
/// The insert type used by the statement.
86328638
pub kind: MergeInsertKind,
86338639
}
@@ -8667,9 +8673,16 @@ pub enum MergeAction {
86678673
/// ```sql
86688674
/// UPDATE SET quantity = T.quantity + S.quantity
86698675
/// ```
8670-
Update { assignments: Vec<Assignment> },
8676+
Update {
8677+
/// The `UPDATE` token that starts the sub-expression.
8678+
update_token: AttachedToken,
8679+
assignments: Vec<Assignment>,
8680+
},
86718681
/// A plain `DELETE` clause
8672-
Delete,
8682+
Delete {
8683+
/// The `DELETE` token that starts the sub-expression.
8684+
delete_token: AttachedToken,
8685+
},
86738686
}
86748687

86758688
impl Display for MergeAction {
@@ -8678,10 +8691,10 @@ impl Display for MergeAction {
86788691
MergeAction::Insert(insert) => {
86798692
write!(f, "INSERT {insert}")
86808693
}
8681-
MergeAction::Update { assignments } => {
8694+
MergeAction::Update { assignments, .. } => {
86828695
write!(f, "UPDATE SET {}", display_comma_separated(assignments))
86838696
}
8684-
MergeAction::Delete => {
8697+
MergeAction::Delete { .. } => {
86858698
write!(f, "DELETE")
86868699
}
86878700
}
@@ -8700,6 +8713,8 @@ impl Display for MergeAction {
87008713
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
87018714
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
87028715
pub struct MergeClause {
8716+
/// The `WHEN` token that starts the sub-expression.
8717+
pub when_token: AttachedToken,
87038718
pub clause_kind: MergeClauseKind,
87048719
pub predicate: Option<Expr>,
87058720
pub action: MergeAction,
@@ -8708,6 +8723,7 @@ pub struct MergeClause {
87088723
impl Display for MergeClause {
87098724
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
87108725
let MergeClause {
8726+
when_token: _,
87118727
clause_kind,
87128728
predicate,
87138729
action,
@@ -8731,10 +8747,12 @@ impl Display for MergeClause {
87318747
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
87328748
pub enum OutputClause {
87338749
Output {
8750+
output_token: AttachedToken,
87348751
select_items: Vec<SelectItem>,
87358752
into_table: Option<SelectInto>,
87368753
},
87378754
Returning {
8755+
returning_token: AttachedToken,
87388756
select_items: Vec<SelectItem>,
87398757
},
87408758
}
@@ -8743,6 +8761,7 @@ impl fmt::Display for OutputClause {
87438761
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
87448762
match self {
87458763
OutputClause::Output {
8764+
output_token: _,
87468765
select_items,
87478766
into_table,
87488767
} => {
@@ -8754,7 +8773,10 @@ impl fmt::Display for OutputClause {
87548773
}
87558774
Ok(())
87568775
}
8757-
OutputClause::Returning { select_items } => {
8776+
OutputClause::Returning {
8777+
returning_token: _,
8778+
select_items,
8779+
} => {
87588780
f.write_str("RETURNING ")?;
87598781
display_comma_separated(select_items).fmt(f)
87608782
}

0 commit comments

Comments
 (0)