Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB2 Grammar for Upsert #79

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

jonkerw85
Copy link

Added the upsert functionality (Laravel 8.10 in, https://laravel-news.com/laravel-8-10-0) for de DB2 driver.

Source :

Resulting SQL (don't mind table and column names. This database was written in a time DB2 had length limitations on names for columns and tables)

SQL Example :

merge INTO trbpar AS temp
USING (VALUES (CAST(? AS VARCHAR(1)), CAST(? AS VARCHAR(5)), CAST(? AS VARCHAR(2)), CAST(? AS VARCHAR(8)), CAST(? AS VARCHAR(5)), CAST(? AS VARCHAR(1)), CAST(? AS VARCHAR(4)), CAST(? AS VARCHAR(6)), CAST(? AS VARCHAR(5)), CAST(? AS VARCHAR(1)), CAST(? AS VARCHAR(1)), CAST(? AS VARCHAR(1)))) AS merge (tbea#mv, tbeat#, tbebdfam, tbed#i, tbema#, tbemts, tbepn#, tbet#i, tbeusri, tbey#1, tbey#po, tbey#u)
ON temp.tbebdfam = merge.tbebdfam
AND temp.tbepn# = merge.tbepn#
AND temp.tbema# = merge.tbema#
WHEN matched THEN
UPDATE SET temp.tbea#mv = merge.tbea#mv,
temp.tbebdfam = merge.tbebdfam,
temp.tbeusri = merge.tbeusri,
temp.tbepn# = merge.tbepn#,
temp.tbemts = merge.tbemts,
temp.tbey#u = merge.tbey#u,
temp.tbey#po = merge.tbey#po,
temp.tbey#1 = merge.tbey#1,
temp.tbed#i = merge.tbed#i,
temp.tbet#i = merge.tbet#i,
temp.tbema# = merge.tbema#,
temp.tbeat# = merge.tbeat#
WHEN NOT matched THEN
INSERT (tbea#mv,
tbeat#,
tbebdfam,
tbed#i,
tbema#,
tbemts,
tbepn#,
tbet#i,
tbeusri,
tbey#1,
tbey#po,
tbey#u)
VALUES (merge.tbea#mv,
merge.tbeat#,
merge.tbebdfam,
merge.tbed#i,
merge.tbema#,
merge.tbemts,
merge.tbepn#,
merge.tbet#i,
merge.tbeusri,
merge.tbey#1,
merge.tbey#po,
merge.tbey#u)

@jonkerw85 jonkerw85 changed the title Upsert cooperl DB2 Grammar for Upsert Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant