345 questions
2 votes
2 answers
199 views
How to avoid "ON CONFLICT DO UPDATE command cannot affect row a second time" error in WITH statement
I have two tables: demo at db<>fiddle Table keywords has two columns id and v (which hold the keyword's value) create table keywords( id int generated always as identity primary key ,v text ...
0 votes
1 answer
95 views
SQL Merge WHEN NOT MATCHED BY SOURCE THEN on filtered source and targed tables [closed]
I have a 2 tables with PARENT-CHILD relationship and their "snapshot" versions: CREATE TABLE Parent( ParentId int ) CREATE TABLE Child( ChildId int, ParentId int, ColA int, ) ...
0 votes
1 answer
61 views
Merge statement with Date for DB2
I have tried to fix this for several ways, both by binding as String, Date and now by omitting the Date from the binding. Please see the code block below which illustrate the example where I have ...
-1 votes
1 answer
137 views
Incorrect syntax near semicolon after `MERGE` [closed]
EDIT: I believe the root of the problem is how dbeaver behaves with semicolons and GO. This issue is not reproducible outside of dbeaver, hopefully this is helpful to someone. I've been handed some ...
-1 votes
2 answers
231 views
MERGE runs WHEN NOT MATCHED clause unexpectedly
I'm running a MERGE statement in SQL Server where the source table has a single row with a requestMaterialId that matches with a row in the target table. My expectation is that the WHEN MATCHED clause ...
2 votes
1 answer
449 views
MERGE RETURNING into temp table without a CTE
Is something like this possible without having to use WITH? Can CREATE TEMP TABLE temp AS be used instead of creating the temp table manually? CREATE TEMP TABLE temp ( action text, winery_id ...
0 votes
0 answers
117 views
SQL Server Merge update only if different
I have a merge, correlating on a primary key, I want to insert when the id doesn't exist in target, delete if it doesn't exist in source, and update if fields on the record are different. MERGE INTO ...
0 votes
1 answer
31 views
Update table column based on join in Oracle
I have 2 tables like below: select vsat_detail_id, sap_id, AZIMUTH_GSAT_16 from tbl_vsat_mst_detail_2409 where vsat_detail_id = 104; Table 1 select vsat_id, sap_id, azimuth_60_e from ...
0 votes
1 answer
263 views
Merge Statement with Select query as input not working in AWS Athena
I am writing the following merge query in AWS Athena, according to the documentation a table or a query can be input to the merge statement. I have a iceberg table in Athena that needs to be inserted ...
0 votes
1 answer
60 views
How to escape the / while updating the columns using merge in spark.sql
I was trying to update my table using the merge statement. One of my column have the /. when I try to update with the column name. Below is my code query = """merge into dfFullView as t ...
0 votes
2 answers
49 views
Creating a Procedure using Merge Into’ but getting Syntax Errors SQL Developer/DBVisualizer
I have 5 tables in total. I wrote the initial sub query to gather the proper Pace IDs/Product IDs according to the Master Product ID. However, when I go to join to the Status/Record Tables in my ...
0 votes
1 answer
167 views
SQL Server merge performance [closed]
Performing a merge against a table with 40 million rows takes many hours, on a database server with significant horsepower (64 GB memory, 16 cores). I load data into a staging table via SqlBulkCopy, ...
0 votes
1 answer
104 views
SQL Merge statement on a "Join Table" of a many-to-many relationship
As a title says - I have two tables, Address with the key addrId (int, identity), and Company with the key coId (int, identity). The relationship between them is many-to-many, so I have a 3rd table ...
0 votes
2 answers
74 views
SQL query: merge 2 tables
I need to generate a SQL query for the following case: First table: column1 A B Second table: column2 1 2 3 4 I want to create a query so the result will be like this: column1 column2 A 1 A 2 A 3 A 4 ...
1 vote
1 answer
466 views
Throwing exception in SQL MERGE clause is not possible
I want to merge 2 tables only if all of the IDs in the source table exist in the target table. But it is not possible to throw exceptions inside merge clause. What are my alternative options to ...