@@ -8635,6 +8635,7 @@ impl Display for MergeInsertKind {
86358635///
86368636/// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/merge)
86378637/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement)
8638+ /// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/MERGE.html)
86388639#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
86398640#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
86408641#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
@@ -8653,14 +8654,22 @@ pub struct MergeInsertExpr {
86538654 pub kind_token : AttachedToken ,
86548655 /// The insert type used by the statement.
86558656 pub kind : MergeInsertKind ,
8657+ /// An optional condition to restrict the insertion (Oracle specific)
8658+ ///
8659+ /// Enabled via [`Dialect::supports_merge_insert_predicate`](crate::dialect::Dialect::supports_merge_insert_predicate).
8660+ pub insert_predicate : Option < Expr > ,
86568661}
86578662
86588663impl Display for MergeInsertExpr {
86598664 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
86608665 if !self . columns . is_empty ( ) {
86618666 write ! ( f, "({}) " , display_comma_separated( self . columns. as_slice( ) ) ) ?;
86628667 }
8663- write ! ( f, "{}" , self . kind)
8668+ write ! ( f, "{}" , self . kind) ?;
8669+ if let Some ( predicate) = self . insert_predicate . as_ref ( ) {
8670+ write ! ( f, " WHERE {}" , predicate) ?;
8671+ }
8672+ Ok ( ( ) )
86648673 }
86658674}
86668675
@@ -8673,6 +8682,7 @@ impl Display for MergeInsertExpr {
86738682///
86748683/// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/merge)
86758684/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement)
8685+ /// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/MERGE.html)
86768686#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
86778687#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
86788688#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
@@ -8693,7 +8703,16 @@ pub enum MergeAction {
86938703 Update {
86948704 /// The `UPDATE` token that starts the sub-expression.
86958705 update_token : AttachedToken ,
8706+ /// The update assiment expressions
86968707 assignments : Vec < Assignment > ,
8708+ /// `where_clause` for the update (Oralce specific)
8709+ ///
8710+ /// Enabled via [`Dialect::supports_merge_update_predicate`](crate::dialect::Dialect::supports_merge_update_predicate).
8711+ update_predicate : Option < Expr > ,
8712+ /// `delete_clause` for the update "delete where" (Oracle specific)
8713+ ///
8714+ /// Enabled via [`Dialect::supports_merge_update_delete_predicate`](crate::dialect::Dialect::supports_merge_update_delete_predicate).
8715+ delete_predicate : Option < Expr > ,
86978716 } ,
86988717 /// A plain `DELETE` clause
86998718 Delete {
@@ -8708,8 +8727,20 @@ impl Display for MergeAction {
87088727 MergeAction :: Insert ( insert) => {
87098728 write ! ( f, "INSERT {insert}" )
87108729 }
8711- MergeAction :: Update { assignments, .. } => {
8712- write ! ( f, "UPDATE SET {}" , display_comma_separated( assignments) )
8730+ MergeAction :: Update {
8731+ update_token : _,
8732+ assignments,
8733+ update_predicate,
8734+ delete_predicate,
8735+ } => {
8736+ write ! ( f, "UPDATE SET {}" , display_comma_separated( assignments) ) ?;
8737+ if let Some ( predicate) = update_predicate. as_ref ( ) {
8738+ write ! ( f, " WHERE {predicate}" ) ?;
8739+ }
8740+ if let Some ( predicate) = delete_predicate. as_ref ( ) {
8741+ write ! ( f, " DELETE WHERE {predicate}" ) ?;
8742+ }
8743+ Ok ( ( ) )
87138744 }
87148745 MergeAction :: Delete { .. } => {
87158746 write ! ( f, "DELETE" )
0 commit comments