Chantal Loncle
04/19/2024, 4:14 AMMERGE INTO target_table AS t
USING source_table AS s
ON s.id = t.id
WHEN NOT MATCHED THEN
INSERT (id, name, amount)
VALUES (s.id, s.name, s.amount)
WHEN MATCHED AND s.amount < 42 THEN
UPDATE SET amount = t.amount + s.amount
WHEN MATCHED THEN
DELETE;
Please react with the option below that reads better to you, or leave a comment 🧵 with an alternative name 🤔
Here's DSL option 1️⃣:
TargetTable.mergeFrom(SourceTable) {
insertWhenNotMatched {
// insert values
}
updateWhenMatched(and = SourceTable.amount less 42) {
// update values
}
deleteWhenMatched()
}
And here's DSL option 2️⃣:
TargetTable.mergeFrom(SourceTable) {
whenNotMatchedInsert {
// insert values
}
whenMatchedUpdate(and = SourceTable.amount less 42) {
// update values
}
whenMatchedDelete()
}
Thanks in advance for your input thank you colorDominik Sandjaja
04/19/2024, 6:05 AM