I need to insert non-duplicated values... This "merge with self-reference" is not working as expected, but not generated a error message... Can I use similar thing?
MERGE INTO mydb.mytab AS Tref
USING mydb.mytab AS T ON Tref.id=T.id
WHEN NOT MATCHED THEN INSERT VALUES (123, 'etc');
(update but not change the question) Seems that other construction, as suggested here, is
INTO INTO mydb.mytab
SELECT t1.*
FROM ( select stack(2, 123,'ect1', 20,'etc2') as (id,etc) ) t1
LEFT OUTER JOIN mydb.mytab t2 ON t1.id = t2.id
WHERE t1.id is null
;
it is not elegant (there are other?) but it is working (!). There is some alternative with MERGE?