I have pairs like (<first_value>, <second_value>) and I have table with following structure:
_____________________________________
| id | first_column | second_column |
I need to insert all pairs which do not exist already.
I think that I need something like INSERT IF NOT EXIST but for every pair.
I try use this code:
INSERT INTO <table_name>(<first_column>, <second_column>)
VALUES (CASE
WHEN NOT EXISTS (
SELECT 1
FROM <table_name>
WHERE <first_column> = <pair_1_value_1> AND <second_column> = <pair_1_value_2>
) THEN (<pair_1_value_1>, <pair_1_value_2>)
WHEN NOT EXISTS (
SELECT 1
FROM <table_name>
WHERE <first_column> = <pair_2_value_1> AND <second_column> = <pair_2_value_2>
) THEN (<pair_2_value_1>, <pair_2_value_2>)
.....
END
);
But I get this error: INSERT has more target columns than expressions. Also, I thought it wouldn't work because it would only insert the one line that first passes the condition. As a if - elif - else operators in other programing languages
<table_name>(<first_column>, <second_column>)BTW: please don't use meta-syntax or pseudocode. Use actual code, with actual names.