From a0b65d08cdb9f594d781d383e4301f53b6120421 Mon Sep 17 00:00:00 2001 From: David Wicinas <93669463+dwicinas@users.noreply.github.com> Date: Tue, 2 Jan 2024 11:41:30 -0500 Subject: [PATCH 1/3] Removed mention of DELETE from MERGE topic --- .../epas_compat_sql/65a_merge.mdx | 33 ++----------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/product_docs/docs/epas/15/reference/oracle_compatibility_reference/epas_compat_sql/65a_merge.mdx b/product_docs/docs/epas/15/reference/oracle_compatibility_reference/epas_compat_sql/65a_merge.mdx index 738a4b34e0d..ab385603fa9 100644 --- a/product_docs/docs/epas/15/reference/oracle_compatibility_reference/epas_compat_sql/65a_merge.mdx +++ b/product_docs/docs/epas/15/reference/oracle_compatibility_reference/epas_compat_sql/65a_merge.mdx @@ -6,7 +6,7 @@ redirects: ## Name -`MERGE` — conditionally insert, update, or delete rows of a table. +`MERGE` — conditionally insert or update rows of a table. ## Synopsis @@ -18,7 +18,6 @@ merge_update_clause merge_insert_clause -- where merge_update_clause is WHEN MATCHED THEN UPDATE SET column = value, ... [ WHERE where_condition ] - [ DELETE WHERE where_condition ] -- and merge_insert_clause is WHEN NOT MATCHED THEN @@ -29,7 +28,7 @@ WHEN NOT MATCHED THEN `MERGE` allows you to select rows from one or more sources for update or insertion into a table. You specify the join condition to determine whether to update or insert into the target table. You specify conditional UPDATE and INSERT statements using the WHERE clause in the MERGE statement. -`MERGE` provides a single SQL statement that can conditionally INSERT, UPDATE, or DELETE rows, a task which would otherwise require multiple procedural language statements. +`MERGE` provides a single SQL statement that can conditionally INSERT or UPDATE rows, a task which would otherwise require multiple procedural language statements. For more information, see [MERGE statement](https://www.postgresql.org/docs/current/sql-merge.html). @@ -62,8 +61,6 @@ For more information, see [MERGE statement](https://www.postgresql.org/docs/curr Specify the where_condition if you want the database to execute the update operation only if the specified condition is true. The condition can refer to either the data source or the target table. If the condition is not true, then the database skips the update operation when merging the row into the table. - Specify the DELETE where_condition to clean up data in a table while populating or updating it. The only rows affected by this clause are those rows in the target table that are updated by the merge operation. The DELETE WHERE condition evaluates the updated value, not the original value that was evaluated by the UPDATE SET ... WHERE condition. If a row of the target table meets the DELETE condition but is not included in the join defined by the ON clause, then it is not deleted. - You can specify this clause by itself or with the merge_insert_clause. If you specify both, then they can be in either order. `merge_insert_clause` @@ -114,29 +111,3 @@ WHEN MATCHED THEN WHEN NOT MATCHED THEN INSERT VALUES (s.sid, s.delta); ``` - -This example shows how to UPDATE, INSERT, and conditionally DELETE rows on the target table using MERGE statement: - -```sql -MERGE INTO target t -USING source s -ON (t.tid = s.sid) -WHEN MATCHED THEN - UPDATE SET t.balance = t.balance + 100 - DELETE WHERE sid = 1 -WHEN NOT MATCHED THEN - INSERT VALUES (s.sid, s.delta); -``` - -This example shows how to UPDATE, INSERT, and DELETE rows on the target table conditionally using the MERGE statement: - -```sql -MERGE INTO target t -USING source s -ON (t.tid = s.sid) -WHEN MATCHED THEN - UPDATE SET balance = s.delta WHERE balance = 0 - DELETE WHERE sid = 1 -WHEN NOT MATCHED THEN - INSERT VALUES (s.sid, s.delta) WHERE s.sid >= 5; -``` \ No newline at end of file From 2195016683967178ba6e108735ff8664bdb85fa6 Mon Sep 17 00:00:00 2001 From: David Wicinas <93669463+dwicinas@users.noreply.github.com> Date: Tue, 2 Jan 2024 12:03:09 -0500 Subject: [PATCH 2/3] Additional updates based on developer comments in issue --- .../epas_compat_sql/65a_merge.mdx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/product_docs/docs/epas/15/reference/oracle_compatibility_reference/epas_compat_sql/65a_merge.mdx b/product_docs/docs/epas/15/reference/oracle_compatibility_reference/epas_compat_sql/65a_merge.mdx index ab385603fa9..c38293e43a4 100644 --- a/product_docs/docs/epas/15/reference/oracle_compatibility_reference/epas_compat_sql/65a_merge.mdx +++ b/product_docs/docs/epas/15/reference/oracle_compatibility_reference/epas_compat_sql/65a_merge.mdx @@ -30,6 +30,9 @@ WHEN NOT MATCHED THEN `MERGE` provides a single SQL statement that can conditionally INSERT or UPDATE rows, a task which would otherwise require multiple procedural language statements. +!!! Note: + In version 15, EDB Postgres Advanced Server provides only partial support for Oracle-compatible MERGE syntax.!!! + For more information, see [MERGE statement](https://www.postgresql.org/docs/current/sql-merge.html). @@ -111,3 +114,15 @@ WHEN MATCHED THEN WHEN NOT MATCHED THEN INSERT VALUES (s.sid, s.delta); ``` + +This example shows how to INSERT and UDPATE rows on the target table conditionally using the MERGE statement: + +```sql +MERGE INTO target t +USING source s +ON (t.tid = s.sid) +WHEN MATCHED THEN + UPDATE SET balance = s.delta WHERE balance = 0 +WHEN NOT MATCHED THEN + INSERT VALUES (s.sid, s.delta) WHERE s.sid >= 5; +``` \ No newline at end of file From 649ee2646239b35faa12f93901bbfca7b1ebb520 Mon Sep 17 00:00:00 2001 From: David Wicinas <93669463+dwicinas@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:36:25 -0500 Subject: [PATCH 3/3] minor edit based on input from Shruthi Gowda --- .../epas_compat_sql/65a_merge.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/product_docs/docs/epas/15/reference/oracle_compatibility_reference/epas_compat_sql/65a_merge.mdx b/product_docs/docs/epas/15/reference/oracle_compatibility_reference/epas_compat_sql/65a_merge.mdx index c38293e43a4..20de741c56f 100644 --- a/product_docs/docs/epas/15/reference/oracle_compatibility_reference/epas_compat_sql/65a_merge.mdx +++ b/product_docs/docs/epas/15/reference/oracle_compatibility_reference/epas_compat_sql/65a_merge.mdx @@ -115,7 +115,7 @@ WHEN NOT MATCHED THEN INSERT VALUES (s.sid, s.delta); ``` -This example shows how to INSERT and UDPATE rows on the target table conditionally using the MERGE statement: +This example shows how to conditionally UPDATE and INSERT rows on the target table using the MERGE statement: ```sql MERGE INTO target t