Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4064,6 +4064,8 @@ pub enum Statement {
/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement)
/// [MSSQL](https://learn.microsoft.com/en-us/sql/t-sql/statements/merge-transact-sql?view=sql-server-ver16)
Merge {
/// The `MERGE` token that starts the statement.
merge_token: AttachedToken,
/// optional INTO keyword
into: bool,
/// Specifies the table to merge
Expand All @@ -4088,7 +4090,6 @@ pub enum Statement {
/// Table flag
table_flag: Option<ObjectName>,
/// Table name

#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
table_name: ObjectName,
has_as: bool,
Expand Down Expand Up @@ -5488,6 +5489,7 @@ impl fmt::Display for Statement {
write!(f, "RELEASE SAVEPOINT {name}")
}
Statement::Merge {
merge_token: _,
into,
table,
source,
Expand Down Expand Up @@ -8620,6 +8622,8 @@ impl Display for MergeInsertKind {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct MergeInsertExpr {
/// The `INSERT` token that starts the sub-expression.
pub insert_token: AttachedToken,
/// Columns (if any) specified by the insert.
///
/// Example:
Expand All @@ -8628,6 +8632,8 @@ pub struct MergeInsertExpr {
/// INSERT (product, quantity) ROW
/// ```
pub columns: Vec<Ident>,
/// The token, `[VALUES | ROW]` starting `kind`.
pub kind_token: AttachedToken,
/// The insert type used by the statement.
pub kind: MergeInsertKind,
}
Expand Down Expand Up @@ -8667,9 +8673,16 @@ pub enum MergeAction {
/// ```sql
/// UPDATE SET quantity = T.quantity + S.quantity
/// ```
Update { assignments: Vec<Assignment> },
Update {
/// The `UPDATE` token that starts the sub-expression.
update_token: AttachedToken,
assignments: Vec<Assignment>,
},
/// A plain `DELETE` clause
Delete,
Delete {
/// The `DELETE` token that starts the sub-expression.
delete_token: AttachedToken,
},
}

impl Display for MergeAction {
Expand All @@ -8678,10 +8691,10 @@ impl Display for MergeAction {
MergeAction::Insert(insert) => {
write!(f, "INSERT {insert}")
}
MergeAction::Update { assignments } => {
MergeAction::Update { assignments, .. } => {
write!(f, "UPDATE SET {}", display_comma_separated(assignments))
}
MergeAction::Delete => {
MergeAction::Delete { .. } => {
write!(f, "DELETE")
}
}
Expand All @@ -8700,6 +8713,8 @@ impl Display for MergeAction {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct MergeClause {
/// The `WHEN` token that starts the sub-expression.
pub when_token: AttachedToken,
pub clause_kind: MergeClauseKind,
pub predicate: Option<Expr>,
pub action: MergeAction,
Expand All @@ -8708,6 +8723,7 @@ pub struct MergeClause {
impl Display for MergeClause {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let MergeClause {
when_token: _,
clause_kind,
predicate,
action,
Expand All @@ -8731,10 +8747,12 @@ impl Display for MergeClause {
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum OutputClause {
Output {
output_token: AttachedToken,
select_items: Vec<SelectItem>,
into_table: Option<SelectInto>,
},
Returning {
returning_token: AttachedToken,
select_items: Vec<SelectItem>,
},
}
Expand All @@ -8743,6 +8761,7 @@ impl fmt::Display for OutputClause {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
OutputClause::Output {
output_token: _,
select_items,
into_table,
} => {
Expand All @@ -8754,7 +8773,10 @@ impl fmt::Display for OutputClause {
}
Ok(())
}
OutputClause::Returning { select_items } => {
OutputClause::Returning {
returning_token: _,
select_items,
} => {
f.write_str("RETURNING ")?;
display_comma_separated(select_items).fmt(f)
}
Expand Down
Loading
Loading