INSERT INTO my_table (field_1, field_2)
SELECT val_1, val_2
FROM my_table
WHERE NOT EXISTS (SELECT field_1
FROM my_table
WHERE field_2 = val_2)
LIMIT 1
I can not use unique index on field_2 field. I'm trying to insert if not exists a tuple with field2 = val_2. Without the "where" clause, this insert. With the "where" clause EVEN WHEN EMPTY TABLE, it won't insert.
Any help on that?