345 questions
2
votes
2
answers
180
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
60
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
2
answers
229
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 ...
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
253
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
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
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 ...
1
vote
1
answer
461
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 ...
-3
votes
1
answer
100
views
MERGE will not work on production server as it is still SQL Server 2012
I have the following script which works on our SQL Server 2016, but throws the following error on production, which unfortunately is still running SQL Server 2012:
Msg 325, Level 15, State 1, ...
0
votes
2
answers
272
views
ingore duplicate in merge SQL on Snowflake
I have two tables:
src:
ID
model
accy
delivery_date
ETA
call_off
department
style
duration
plant
123abc
xxyy
MM
2022-12-14T00:00:00.000Z
2022-10-20T00:00:00.000Z
2023-01-17T00:00:00.000Z
paint
pink
3....
1
vote
2
answers
366
views
BigQuery Update a Repeated column in a Table using another table
I am trying to write an update or merge BigQuery SQL to update the data_profile.name of table1 (repeated column) using another reference table having dataprofile data of table2 (flattendata).
Using ...
0
votes
1
answer
31
views
Oracle sql - join multiple tables in merge query
I need to get transaction_dates in transactions table to write on a column in a table named payment_plan. But i need to do this operation just for polices that has payment_method as directdebit and ...
-4
votes
1
answer
652
views
MERGE update with duplicates
I am trying to UPDATE target table but in source table I have duplicate data. I am trying in Azure SQL Server database. All will be ok with HASHBYTES but if I remove HASHBYTES it will raise an error:
...
0
votes
1
answer
349
views
Updating Target table when the data is not available in Source
In sql I want to update a table when the data is not present in source.
Target Table
Source Table
so now for EmpId 1 is not having courseid 3 in source I need to update it need to change isthere ...
1
vote
1
answer
80
views
Merge fails for OffsetDateTime when offset is UTC (+00:00)
I’m having an issue with HSQLDB and MERGE with the following merge logic if I use an OffsetDateTime with offset +00:00
private static final String CREATE_TABLE_SQL =
"create ...
0
votes
2
answers
369
views
oracle "merge into" too slow
i'm trying to update a column in a table using the id of another table only if one or two field match each other. Sadly the query run very slowly and i don't understand why.
PS:(the checked fields for ...
0
votes
1
answer
177
views
Backfill data based or insert new records based on matching criteria
I have the following effective dated table with several thousands records that would need to be updated/inserted based on certain criteria.
Table Car_Specification:
Effective_Date
Car_ID
Num_Wheels
...
0
votes
1
answer
516
views
PySpark Delete Specific Rows Without Primary Key
I am trying to make up for PySpark's lack of 'WHEN NOT MATCHED BY SOURCE' in MERGE statements. I want to delete rows from a table when there are no matching rows in another table. However, my table ...
0
votes
0
answers
169
views
BQ - Merge command inserts more than one row
Ran the following query which I expected to insert or update only one row. But the query inserted 24923 rows which is the total number of rows existing in the table at the time of running this command....
1
vote
1
answer
1k
views
DBT Merge Partition Pruning
This is my first time working with dbt! I have successfully implemented an incremental model using #db-bigquery with following config like so
{{ config(
materialized='incremental',
alias='...
0
votes
0
answers
552
views
SQL MERGE with variable number of values
I would like to know if a MERGE statement could, somehow, be written to support value sets with different column counts?
First, if we had a table that is defined as follows:
CREATE TABLE [Example]
(
...
2
votes
1
answer
823
views
Lock level on MERGE statement
Does anyone know what is the lock level (row, table) on PostgreSQL MERGE command? I tried to dig deep on the documentation but I couldn't find anything that could clarify my mind. If anyone have a ...
0
votes
1
answer
642
views
Convert MERGE to UPDATE
I have the following MERGE statement.Is there a way to convert this into an update statement without using MERGE?
MERGE INTO tab1
USING (SELECT tab1.col1, tab2.col2
FROM tab1, tab2
...
1
vote
1
answer
391
views
How to add two conditions in merge statement using rowid and rownum
CREATE SEQUENCE e_demo2_tab_sq;
CREATE TABLE e_demo2_tab
(
tab_id NUMBER(10) DEFAULT e_demo2_tab_sq.nextval NOT NULL,
e_id NUMBER(10),
e_uuid NUMBER(10),
seq_cnt NUMBER(10)
)...
6
votes
3
answers
11k
views
how to delete rows with matching ID that were not affected by MERGE?
I have a table with an auto incrementing id and a unique constraint across two columns, keycol1 and keycol2.
Suppose the table has this data:
H| (id, keycol1, keycol2, col1, col2)
| (1, 'A', 'B', ...