-
Notifications
You must be signed in to change notification settings - Fork 89
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
Add note warning about NULL merge keys #196
Conversation
Thank you for the PR! As you wrote, merge mode doesn't work for
Following SQL will work for (tableA.colA1 = tableB.colB1 or tableA.colA1 is null and tableB.colB1 is null) and (tableA.colA2 = tableB.colB2 or tableA.colA2 is null and tableB.colB2 is null) ... Do you think it is useful to support |
Hmm the query currently winds up looking something like this:
So I'm not sure if your technique would be able to be applied to this style of query. |
Thank you for your reply. The above SQL can be modified to support INSERT INTO tableB (colB1, colB2) UNION ALL ( SELECT colA1, colA2 FROM tableA WHERE NOT EXISTS (SELECT * FROM tableB WHERE (colB1 = colA1 OR colB1 IS NULL AND colA1 IS NULL) AND (colB2 = colA2 OR colB2 IS NULL AND colA2 IS NULL)) ) But the SQL may be slower than the original SQL. |
Wouldn't using |
The old wrong SQL is as follows. ... SELECT col1, col2, ... FROM temp WHERE NOT EXISTS (SELECT 1 FROM temp, target WHERE temp.col1 = target.col1 AND temp.col2 = target.col2 AND ... The slip is selecting from temporary table in subquery. ... SELECT col1, col2, ... FROM temp WHERE NOT EXISTS (SELECT 1 FROM target WHERE temp.col1 = target.col1 AND temp.col2 = target.col2 AND ... |
I think the problem will still exist where |
@mjalkio CREATE TABLE temp ( col1 int, col2 int ); INSERT INTO temp VALUES(11, 21); INSERT INTO temp VALUES(12, 22); CREATE TABLE target ( col1 int, col2 int ); INSERT INTO target VALUES(11, 21); INSERT INTO target VALUES(13, 23); SELECT col1, col2 FROM temp WHERE NOT EXISTS (SELECT 1 FROM temp, target WHERE temp.col1 = target.col1 AND temp.col2 = target.col2); col1 col2 -------------------------- SELECT col1, col2 FROM temp WHERE NOT EXISTS (SELECT 1 FROM target WHERE temp.col1 = target.col1 AND temp.col2 = target.col2); col1 col2 -------------------------- 12 22 |
Hm, you're right. That's definitely not how I imagined that query would work, but it does! |
As the description says, I just added a warning. I had a situation where one of my merge keys (I was using three) was allowed to be
NULL
and it didn't work because Redshift can't compareNULL = NULL
.Unfortunately, I don't think there's a way to support
NULL
merge keys.