@@ -8626,6 +8626,7 @@ impl Display for MergeInsertKind {
86268626///
86278627/// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/merge)
86288628/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement)
8629+ /// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/MERGE.html)
86298630#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
86308631#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
86318632#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
@@ -8644,14 +8645,22 @@ pub struct MergeInsertExpr {
86448645 pub kind_token : AttachedToken ,
86458646 /// The insert type used by the statement.
86468647 pub kind : MergeInsertKind ,
8648+ /// An optional condition to restrict the insertion (Oracle specific)
8649+ ///
8650+ /// Enabled via [`Dialect::supports_merge_insert_predicate`](crate::dialect::Dialect::supports_merge_insert_predicate).
8651+ pub insert_predicate : Option < Expr > ,
86478652}
86488653
86498654impl Display for MergeInsertExpr {
86508655 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
86518656 if !self . columns . is_empty ( ) {
86528657 write ! ( f, "({}) " , display_comma_separated( self . columns. as_slice( ) ) ) ?;
86538658 }
8654- write ! ( f, "{}" , self . kind)
8659+ write ! ( f, "{}" , self . kind) ?;
8660+ if let Some ( predicate) = self . insert_predicate . as_ref ( ) {
8661+ write ! ( f, " WHERE {}" , predicate) ?;
8662+ }
8663+ Ok ( ( ) )
86558664 }
86568665}
86578666
@@ -8664,6 +8673,7 @@ impl Display for MergeInsertExpr {
86648673///
86658674/// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/merge)
86668675/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement)
8676+ /// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/MERGE.html)
86678677#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
86688678#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
86698679#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
@@ -8684,7 +8694,16 @@ pub enum MergeAction {
86848694 Update {
86858695 /// The `UPDATE` token that starts the sub-expression.
86868696 update_token : AttachedToken ,
8697+ /// The update assiment expressions
86878698 assignments : Vec < Assignment > ,
8699+ /// `where_clause` for the update (Oralce specific)
8700+ ///
8701+ /// Enabled via [`Dialect::supports_merge_update_predicate`](crate::dialect::Dialect::supports_merge_update_predicate).
8702+ update_predicate : Option < Expr > ,
8703+ /// `delete_clause` for the update "delete where" (Oracle specific)
8704+ ///
8705+ /// Enabled via [`Dialect::supports_merge_update_delete_predicate`](crate::dialect::Dialect::supports_merge_update_delete_predicate).
8706+ delete_predicate : Option < Expr > ,
86888707 } ,
86898708 /// A plain `DELETE` clause
86908709 Delete {
@@ -8699,8 +8718,20 @@ impl Display for MergeAction {
86998718 MergeAction :: Insert ( insert) => {
87008719 write ! ( f, "INSERT {insert}" )
87018720 }
8702- MergeAction :: Update { assignments, .. } => {
8703- write ! ( f, "UPDATE SET {}" , display_comma_separated( assignments) )
8721+ MergeAction :: Update {
8722+ update_token : _,
8723+ assignments,
8724+ update_predicate,
8725+ delete_predicate,
8726+ } => {
8727+ write ! ( f, "UPDATE SET {}" , display_comma_separated( assignments) ) ?;
8728+ if let Some ( predicate) = update_predicate. as_ref ( ) {
8729+ write ! ( f, " WHERE {predicate}" ) ?;
8730+ }
8731+ if let Some ( predicate) = delete_predicate. as_ref ( ) {
8732+ write ! ( f, " DELETE WHERE {predicate}" ) ?;
8733+ }
8734+ Ok ( ( ) )
87048735 }
87058736 MergeAction :: Delete { .. } => {
87068737 write ! ( f, "DELETE" )
0 commit comments